Skip to content

Commit

Permalink
Consolidate configuration of Sidekiq::Testing.fake! setup (mastodon…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Nov 23, 2023
1 parent c810b19 commit 973597c
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 65 deletions.
8 changes: 1 addition & 7 deletions spec/controllers/api/v1/statuses/reblogs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:statuses', application: app) }

context 'with an oauth token' do
around do |example|
Sidekiq::Testing.fake! do
example.run
end
end

context 'with an oauth token', :sidekiq_fake do
before do
allow(controller).to receive(:doorkeeper_token) { token }
end
Expand Down
10 changes: 4 additions & 6 deletions spec/controllers/settings/exports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@
expect(response).to redirect_to(settings_export_path)
end

it 'queues BackupWorker job by 1' do
Sidekiq::Testing.fake! do
expect do
post :create
end.to change(BackupWorker.jobs, :size).by(1)
end
it 'queues BackupWorker job by 1', :sidekiq_fake do
expect do
post :create
end.to change(BackupWorker.jobs, :size).by(1)
end
end
end
9 changes: 1 addition & 8 deletions spec/lib/activitypub/activity/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
stub_request(:get, 'http://example.com/emojib.png').to_return(body: attachment_fixture('emojo.png'), headers: { 'Content-Type' => 'application/octet-stream' })
end

describe 'processing posts received out of order' do
describe 'processing posts received out of order', :sidekiq_fake do
let(:follower) { Fabricate(:account, username: 'bob') }

let(:object_json) do
Expand Down Expand Up @@ -77,13 +77,6 @@ def activity_for_object(json)
follower.follow!(sender)
end

around do |example|
Sidekiq::Testing.fake! do
example.run
Sidekiq::Worker.clear_all
end
end

it 'correctly processes posts and inserts them in timelines', :aggregate_failures do
# Simulate a temporary failure preventing from fetching the parent post
stub_request(:get, object_json[:id]).to_return(status: 500)
Expand Down
10 changes: 4 additions & 6 deletions spec/models/admin/account_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@
expect(target_account).to be_suspended
end

it 'queues Admin::SuspensionWorker by 1' do
Sidekiq::Testing.fake! do
expect do
subject
end.to change { Admin::SuspensionWorker.jobs.size }.by 1
end
it 'queues Admin::SuspensionWorker by 1', :sidekiq_fake do
expect do
subject
end.to change { Admin::SuspensionWorker.jobs.size }.by 1
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ def sign_in(resource, _deprecated = nil, scope: nil)
self.use_transactional_tests = true
end

config.around(:each, :sidekiq_fake) do |example|
Sidekiq::Testing.fake! do
example.run
Sidekiq::Worker.clear_all
end
end

config.before :each, type: :cli do
stub_stdout
stub_reset_connection_pools
Expand Down
8 changes: 1 addition & 7 deletions spec/requests/api/v1/statuses/favourites_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,13 @@
end
end

describe 'POST /api/v1/statuses/:status_id/unfavourite' do
describe 'POST /api/v1/statuses/:status_id/unfavourite', :sidekiq_fake do
subject do
post "/api/v1/statuses/#{status.id}/unfavourite", headers: headers
end

let(:status) { Fabricate(:status) }

around do |example|
Sidekiq::Testing.fake! do
example.run
end
end

it_behaves_like 'forbidden for wrong scope', 'read read:favourites'

context 'with public status' do
Expand Down
9 changes: 1 addition & 8 deletions spec/services/bulk_import_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@
import.update(total_items: import.rows.count)
end

describe '#call' do
around do |example|
Sidekiq::Testing.fake! do
example.run
Sidekiq::Worker.clear_all
end
end

describe '#call', :sidekiq_fake do
context 'when importing follows' do
let(:import_type) { 'following' }
let(:overwrite) { false }
Expand Down
6 changes: 2 additions & 4 deletions spec/services/update_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
end
end

context 'when poll changes' do
context 'when poll changes', :sidekiq_fake do
let(:account) { Fabricate(:account) }
let!(:status) { Fabricate(:status, text: 'Foo', account: account, poll_attributes: { options: %w(Foo Bar), account: account, multiple: false, hide_totals: false, expires_at: 7.days.from_now }) }
let!(:poll) { status.poll }
Expand All @@ -120,9 +120,7 @@
before do
status.update(poll: poll)
VoteService.new.call(voter, poll, [0])
Sidekiq::Testing.fake! do
subject.call(status, status.account_id, text: 'Foo', poll: { options: %w(Bar Baz Foo), expires_in: 5.days.to_i })
end
subject.call(status, status.account_id, text: 'Foo', poll: { options: %w(Bar Baz Foo), expires_in: 5.days.to_i })
end

it 'updates poll' do
Expand Down
18 changes: 6 additions & 12 deletions spec/workers/move_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,9 @@ def mute_account_comment

describe '#perform' do
context 'when both accounts are distant' do
it 'calls UnfollowFollowWorker' do
Sidekiq::Testing.fake! do
subject.perform(source_account.id, target_account.id)
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, false)
Sidekiq::Worker.drain_all
end
it 'calls UnfollowFollowWorker', :sidekiq_fake do
subject.perform(source_account.id, target_account.id)
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, false)
end

include_examples 'common tests'
Expand All @@ -173,12 +170,9 @@ def mute_account_comment
context 'when target account is local' do
let(:target_account) { Fabricate(:account) }

it 'calls UnfollowFollowWorker' do
Sidekiq::Testing.fake! do
subject.perform(source_account.id, target_account.id)
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, true)
Sidekiq::Worker.clear_all
end
it 'calls UnfollowFollowWorker', :sidekiq_fake do
subject.perform(source_account.id, target_account.id)
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, true)
end

include_examples 'common tests'
Expand Down
8 changes: 1 addition & 7 deletions spec/workers/poll_expiration_notify_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
let(:remote?) { false }
let(:poll_vote) { Fabricate(:poll_vote, poll: poll) }

describe '#perform' do
around do |example|
Sidekiq::Testing.fake! do
example.run
end
end

describe '#perform', :sidekiq_fake do
it 'runs without error for missing record' do
expect { worker.perform(nil) }.to_not raise_error
end
Expand Down

0 comments on commit 973597c

Please sign in to comment.