Fix `RSpec/StubbedMock` cop (#25552)
Co-authored-by: Claire <claire.github-309c@sitedethib.com>gh/dev
parent
2e1391fdd2
commit
6c5a2233a8
|
@ -367,17 +367,6 @@ RSpec/PendingWithoutReason:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'spec/models/account_spec.rb'
|
- 'spec/models/account_spec.rb'
|
||||||
|
|
||||||
RSpec/StubbedMock:
|
|
||||||
Exclude:
|
|
||||||
- 'spec/controllers/api/base_controller_spec.rb'
|
|
||||||
- 'spec/controllers/api/v1/media_controller_spec.rb'
|
|
||||||
- 'spec/controllers/auth/registrations_controller_spec.rb'
|
|
||||||
- 'spec/helpers/application_helper_spec.rb'
|
|
||||||
- 'spec/lib/status_filter_spec.rb'
|
|
||||||
- 'spec/lib/status_finder_spec.rb'
|
|
||||||
- 'spec/lib/webfinger_resource_spec.rb'
|
|
||||||
- 'spec/services/activitypub/process_collection_service_spec.rb'
|
|
||||||
|
|
||||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||||
Rails/ApplicationController:
|
Rails/ApplicationController:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
|
|
@ -88,10 +88,11 @@ describe Api::BaseController do
|
||||||
Mastodon::NotPermittedError => 403,
|
Mastodon::NotPermittedError => 403,
|
||||||
}.each do |error, code|
|
}.each do |error, code|
|
||||||
it "Handles error class of #{error}" do
|
it "Handles error class of #{error}" do
|
||||||
expect(FakeService).to receive(:new).and_raise(error)
|
allow(FakeService).to receive(:new).and_raise(error)
|
||||||
|
|
||||||
get 'error'
|
get 'error'
|
||||||
expect(response).to have_http_status(code)
|
expect(response).to have_http_status(code)
|
||||||
|
expect(FakeService).to have_received(:new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ RSpec.describe Api::V1::MediaController do
|
||||||
describe 'with paperclip errors' do
|
describe 'with paperclip errors' do
|
||||||
context 'when imagemagick cant identify the file type' do
|
context 'when imagemagick cant identify the file type' do
|
||||||
it 'returns http 422' do
|
it 'returns http 422' do
|
||||||
expect_any_instance_of(Account).to receive_message_chain(:media_attachments, :create!).and_raise(Paperclip::Errors::NotIdentifiedByImageMagickError)
|
allow_any_instance_of(Account).to receive_message_chain(:media_attachments, :create!).and_raise(Paperclip::Errors::NotIdentifiedByImageMagickError)
|
||||||
post :create, params: { file: fixture_file_upload('attachment.jpg', 'image/jpeg') }
|
post :create, params: { file: fixture_file_upload('attachment.jpg', 'image/jpeg') }
|
||||||
|
|
||||||
expect(response).to have_http_status(422)
|
expect(response).to have_http_status(422)
|
||||||
|
@ -25,7 +25,7 @@ RSpec.describe Api::V1::MediaController do
|
||||||
|
|
||||||
context 'when there is a generic error' do
|
context 'when there is a generic error' do
|
||||||
it 'returns http 422' do
|
it 'returns http 422' do
|
||||||
expect_any_instance_of(Account).to receive_message_chain(:media_attachments, :create!).and_raise(Paperclip::Error)
|
allow_any_instance_of(Account).to receive_message_chain(:media_attachments, :create!).and_raise(Paperclip::Error)
|
||||||
post :create, params: { file: fixture_file_upload('attachment.jpg', 'image/jpeg') }
|
post :create, params: { file: fixture_file_upload('attachment.jpg', 'image/jpeg') }
|
||||||
|
|
||||||
expect(response).to have_http_status(500)
|
expect(response).to have_http_status(500)
|
||||||
|
|
|
@ -15,20 +15,22 @@ RSpec.describe Auth::RegistrationsController do
|
||||||
it 'redirects if it is in single user mode while it is open for registration' do
|
it 'redirects if it is in single user mode while it is open for registration' do
|
||||||
Fabricate(:account)
|
Fabricate(:account)
|
||||||
Setting.registrations_mode = 'open'
|
Setting.registrations_mode = 'open'
|
||||||
expect(Rails.configuration.x).to receive(:single_user_mode).and_return(true)
|
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(true)
|
||||||
|
|
||||||
get path
|
get path
|
||||||
|
|
||||||
expect(response).to redirect_to '/'
|
expect(response).to redirect_to '/'
|
||||||
|
expect(Rails.configuration.x).to have_received(:single_user_mode)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects if it is not open for registration while it is not in single user mode' do
|
it 'redirects if it is not open for registration while it is not in single user mode' do
|
||||||
Setting.registrations_mode = 'none'
|
Setting.registrations_mode = 'none'
|
||||||
expect(Rails.configuration.x).to receive(:single_user_mode).and_return(false)
|
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(false)
|
||||||
|
|
||||||
get path
|
get path
|
||||||
|
|
||||||
expect(response).to redirect_to '/'
|
expect(response).to redirect_to '/'
|
||||||
|
expect(Rails.configuration.x).to have_received(:single_user_mode)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -77,19 +77,17 @@ describe ApplicationHelper do
|
||||||
|
|
||||||
describe 'open_registrations?' do
|
describe 'open_registrations?' do
|
||||||
it 'returns true when open for registrations' do
|
it 'returns true when open for registrations' do
|
||||||
without_partial_double_verification do
|
allow(Setting).to receive(:[]).with('registrations_mode').and_return('open')
|
||||||
expect(Setting).to receive(:registrations_mode).and_return('open')
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(helper.open_registrations?).to be true
|
expect(helper.open_registrations?).to be true
|
||||||
|
expect(Setting).to have_received(:[]).with('registrations_mode')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns false when closed for registrations' do
|
it 'returns false when closed for registrations' do
|
||||||
without_partial_double_verification do
|
allow(Setting).to receive(:[]).with('registrations_mode').and_return('none')
|
||||||
expect(Setting).to receive(:registrations_mode).and_return('none')
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(helper.open_registrations?).to be false
|
expect(helper.open_registrations?).to be false
|
||||||
|
expect(Setting).to have_received(:[]).with('registrations_mode')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -296,8 +294,9 @@ describe ApplicationHelper do
|
||||||
|
|
||||||
it 'returns site title on production environment' do
|
it 'returns site title on production environment' do
|
||||||
Setting.site_title = 'site title'
|
Setting.site_title = 'site title'
|
||||||
expect(Rails.env).to receive(:production?).and_return(true)
|
allow(Rails.env).to receive(:production?).and_return(true)
|
||||||
expect(helper.title).to eq 'site title'
|
expect(helper.title).to eq 'site title'
|
||||||
|
expect(Rails.env).to have_received(:production?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ describe StatusFilter do
|
||||||
|
|
||||||
context 'when status policy does not allow show' do
|
context 'when status policy does not allow show' do
|
||||||
it 'filters the status' do
|
it 'filters the status' do
|
||||||
expect_any_instance_of(StatusPolicy).to receive(:show?).and_return(false)
|
allow_any_instance_of(StatusPolicy).to receive(:show?).and_return(false)
|
||||||
|
|
||||||
expect(filter).to be_filtered
|
expect(filter).to be_filtered
|
||||||
end
|
end
|
||||||
|
@ -74,7 +74,7 @@ describe StatusFilter do
|
||||||
|
|
||||||
context 'when status policy does not allow show' do
|
context 'when status policy does not allow show' do
|
||||||
it 'filters the status' do
|
it 'filters the status' do
|
||||||
expect_any_instance_of(StatusPolicy).to receive(:show?).and_return(false)
|
allow_any_instance_of(StatusPolicy).to receive(:show?).and_return(false)
|
||||||
|
|
||||||
expect(filter).to be_filtered
|
expect(filter).to be_filtered
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,10 +18,13 @@ describe StatusFinder do
|
||||||
|
|
||||||
it 'raises an error if action is not :show' do
|
it 'raises an error if action is not :show' do
|
||||||
recognized = Rails.application.routes.recognize_path(url)
|
recognized = Rails.application.routes.recognize_path(url)
|
||||||
expect(recognized).to receive(:[]).with(:action).and_return(:create)
|
allow(recognized).to receive(:[]).with(:action).and_return(:create)
|
||||||
expect(Rails.application.routes).to receive(:recognize_path).with(url).and_return(recognized)
|
allow(Rails.application.routes).to receive(:recognize_path).with(url).and_return(recognized)
|
||||||
|
|
||||||
expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
|
expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
|
||||||
|
|
||||||
|
expect(Rails.application.routes).to have_received(:recognize_path)
|
||||||
|
expect(recognized).to have_received(:[])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,14 @@ describe WebfingerResource do
|
||||||
recognized = Rails.application.routes.recognize_path(resource)
|
recognized = Rails.application.routes.recognize_path(resource)
|
||||||
allow(recognized).to receive(:[]).with(:controller).and_return('accounts')
|
allow(recognized).to receive(:[]).with(:controller).and_return('accounts')
|
||||||
allow(recognized).to receive(:[]).with(:username).and_return('alice')
|
allow(recognized).to receive(:[]).with(:username).and_return('alice')
|
||||||
expect(recognized).to receive(:[]).with(:action).and_return('create')
|
allow(recognized).to receive(:[]).with(:action).and_return('create')
|
||||||
|
|
||||||
expect(Rails.application.routes).to receive(:recognize_path).with(resource).and_return(recognized).at_least(:once)
|
expect(Rails.application.routes).to receive(:recognize_path).with(resource).and_return(recognized).at_least(:once)
|
||||||
|
|
||||||
expect do
|
expect do
|
||||||
described_class.new(resource).username
|
described_class.new(resource).username
|
||||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||||
|
expect(recognized).to have_received(:[]).exactly(3).times
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises with a string that doesnt start with URL' do
|
it 'raises with a string that doesnt start with URL' do
|
||||||
|
|
|
@ -70,7 +70,7 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
||||||
let(:forwarder) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/other_account') }
|
let(:forwarder) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/other_account') }
|
||||||
|
|
||||||
it 'does not process payload if no signature exists' do
|
it 'does not process payload if no signature exists' do
|
||||||
expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(nil)
|
allow_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(nil)
|
||||||
expect(ActivityPub::Activity).to_not receive(:factory)
|
expect(ActivityPub::Activity).to_not receive(:factory)
|
||||||
|
|
||||||
subject.call(json, forwarder)
|
subject.call(json, forwarder)
|
||||||
|
@ -79,7 +79,7 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
||||||
it 'processes payload with actor if valid signature exists' do
|
it 'processes payload with actor if valid signature exists' do
|
||||||
payload['signature'] = { 'type' => 'RsaSignature2017' }
|
payload['signature'] = { 'type' => 'RsaSignature2017' }
|
||||||
|
|
||||||
expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(actor)
|
allow_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(actor)
|
||||||
expect(ActivityPub::Activity).to receive(:factory).with(instance_of(Hash), actor, instance_of(Hash))
|
expect(ActivityPub::Activity).to receive(:factory).with(instance_of(Hash), actor, instance_of(Hash))
|
||||||
|
|
||||||
subject.call(json, forwarder)
|
subject.call(json, forwarder)
|
||||||
|
@ -88,7 +88,7 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
||||||
it 'does not process payload if invalid signature exists' do
|
it 'does not process payload if invalid signature exists' do
|
||||||
payload['signature'] = { 'type' => 'RsaSignature2017' }
|
payload['signature'] = { 'type' => 'RsaSignature2017' }
|
||||||
|
|
||||||
expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(nil)
|
allow_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(nil)
|
||||||
expect(ActivityPub::Activity).to_not receive(:factory)
|
expect(ActivityPub::Activity).to_not receive(:factory)
|
||||||
|
|
||||||
subject.call(json, forwarder)
|
subject.call(json, forwarder)
|
||||||
|
|
Reference in New Issue