Skip to content

Commit

Permalink
Use Sidekiq fake! instead of inline! in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski committed Dec 21, 2023
1 parent 1c04135 commit 994a160
Show file tree
Hide file tree
Showing 53 changed files with 62 additions and 70 deletions.
4 changes: 2 additions & 2 deletions spec/controllers/admin/disputes/appeals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
expect(response).to redirect_to(disputes_strike_path(appeal.strike))
end

it 'notifies target account about approved appeal' do
it 'notifies target account about approved appeal', :sidekiq_inline do
expect(UserMailer.deliveries.size).to eq(1)
expect(UserMailer.deliveries.first.to.first).to eq(target_account.user.email)
expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at)))
Expand All @@ -62,7 +62,7 @@
expect(response).to redirect_to(disputes_strike_path(appeal.strike))
end

it 'notifies target account about rejected appeal' do
it 'notifies target account about rejected appeal', :sidekiq_inline do
expect(UserMailer.deliveries.size).to eq(1)
expect(UserMailer.deliveries.first.to.first).to eq(target_account.user.email)
expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.appeal_rejected.subject', date: I18n.l(appeal.created_at)))
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/domain_blocks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
end
end

describe 'PUT #update' do
describe 'PUT #update', :sidekiq_inline do
subject do
post :update, params: { :id => domain_block.id, :domain_block => { domain: 'example.com', severity: new_severity }, 'confirm' => '' }
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/resets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
end

describe 'POST #create' do
describe 'POST #create', :sidekiq_inline do
it 'redirects to admin accounts page' do
expect do
post :create, params: { account_id: account.id }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/v1/conversations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
allow(controller).to receive(:doorkeeper_token) { token }
end

describe 'GET #index' do
describe 'GET #index', :sidekiq_inline do
let(:scopes) { 'read:statuses' }

before do
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/api/v1/statuses/reblogs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +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', :sidekiq_fake do
context 'with an oauth token' do
before do
allow(controller).to receive(:doorkeeper_token) { token }
end
Expand Down Expand Up @@ -46,7 +46,7 @@
end
end

describe 'POST #destroy' do
describe 'POST #destroy', :sidekiq_inline do
context 'with public status' do
let(:status) { Fabricate(:status, account: user.account) }

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/auth/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
expect(controller.current_user).to eq user
end

it 'sends a suspicious sign-in mail' do
it 'sends a suspicious sign-in mail', :sidekiq_inline do
expect(UserMailer.deliveries.size).to eq(1)
expect(UserMailer.deliveries.first.to.first).to eq(user.email)
expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.suspicious_sign_in.subject'))
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/concerns/user_tracking_concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def show
expect(redis.ttl("account:#{user.account_id}:regeneration")).to be >= 0
end

it 'regenerates feed when sign in is older than two weeks' do
it 'regenerates feed when sign in is older than two weeks', :sidekiq_inline do
get :show

expect_updated_sign_in_at(user)
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/disputes/appeals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
post :create, params: { strike_id: strike.id, appeal: { text: 'Foo' } }
end

it 'notifies staff about new appeal' do
it 'notifies staff about new appeal', :sidekiq_inline do
expect(ActionMailer::Base.deliveries.first.to).to eq([admin.email])
end

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/settings/deletes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
delete :destroy, params: { form_delete_confirmation: { password: 'petsmoldoggos' } }
end

it 'removes user record and redirects', :aggregate_failures do
it 'removes user record and redirects', :aggregate_failures, :sidekiq_inline do
expect(response).to redirect_to '/auth/sign_in'
expect(User.find_by(id: user.id)).to be_nil
expect(user.account.reload).to be_suspended
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/settings/exports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
expect(response).to redirect_to(settings_export_path)
end

it 'queues BackupWorker job by 1', :sidekiq_fake do
it 'queues BackupWorker job by 1' do
expect do
post :create
end.to change(BackupWorker.jobs, :size).by(1)
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/accounts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
end
end

context 'with action of `reject`' do
context 'with action of `reject`', :sidekiq_inline do
it 'rejects and removes the account' do
batch_checkbox_for(unapproved_user_account).check

Expand Down
2 changes: 1 addition & 1 deletion 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', :sidekiq_fake do
describe 'processing posts received out of order' do
let(:follower) { Fabricate(:account, username: 'bob') }

let(:object_json) do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/activitypub/activity/delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
expect(Status.find_by(id: status.id)).to be_nil
end

it 'sends delete activity to followers of rebloggers' do
it 'sends delete activity to followers of rebloggers', :sidekiq_inline do
expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/activitypub/activity/move_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
subject.perform
end

context 'when all conditions are met' do
context 'when all conditions are met', :sidekiq_inline do
it 'sets moved account on old account' do
expect(old_account.reload.moved_to_account_id).to eq new_account.id
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/admin/account_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
expect(target_account).to be_suspended
end

it 'queues Admin::SuspensionWorker by 1', :sidekiq_fake do
it 'queues Admin::SuspensionWorker by 1' do
expect do
subject
end.to change { Admin::SuspensionWorker.jobs.size }.by 1
Expand Down
4 changes: 2 additions & 2 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
end
end

describe 'scopes' do
describe 'scopes', :sidekiq_inline do
describe 'recent' do
it 'returns an array of recent users ordered by id' do
first_user = Fabricate(:user)
Expand Down Expand Up @@ -452,7 +452,7 @@
expect(user.confirmed_at).to be_present
end

it 'delivers mails' do
it 'delivers mails', :sidekiq_inline do
expect(ActionMailer::Base.deliveries.count).to eq 2
end
end
Expand Down
8 changes: 2 additions & 6 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

ActiveRecord::Migration.maintain_test_schema!
WebMock.disable_net_connect!(allow: Chewy.settings[:host], allow_localhost: RUN_SYSTEM_SPECS)
Sidekiq::Testing.inline!
Sidekiq.logger = nil

# System tests config
Expand Down Expand Up @@ -96,11 +95,8 @@ 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
config.around(:each, :sidekiq_inline) do |example|
Sidekiq::Testing.inline!(&example)
end

config.before :each, type: :cli do
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/api/v1/featured_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
expect(body).to be_empty
end

it 'deletes the featured tag' do
it 'deletes the featured tag', :sidekiq_inline do
delete "/api/v1/featured_tags/#{id}", headers: headers

featured_tag = FeaturedTag.find_by(id: id)
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/api/v1/notifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let(:scopes) { 'read:notifications write:notifications' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }

describe 'GET /api/v1/notifications' do
describe 'GET /api/v1/notifications', :sidekiq_inline do
subject do
get '/api/v1/notifications', headers: headers, params: params
end
Expand Down
8 changes: 2 additions & 6 deletions spec/requests/api/v1/statuses/favourites_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

RSpec.describe 'Favourites' do
RSpec.describe 'Favourites', :sidekiq_inline do
let(:user) { Fabricate(:user) }
let(:scopes) { 'write:favourites' }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
Expand Down Expand Up @@ -70,7 +70,7 @@
end
end

describe 'POST /api/v1/statuses/:status_id/unfavourite', :sidekiq_fake do
describe 'POST /api/v1/statuses/:status_id/unfavourite' do
subject do
post "/api/v1/statuses/#{status.id}/unfavourite", headers: headers
end
Expand All @@ -88,9 +88,7 @@
subject

expect(response).to have_http_status(200)
expect(user.account.favourited?(status)).to be true

UnfavouriteWorker.drain
expect(user.account.favourited?(status)).to be false
end

Expand All @@ -113,9 +111,7 @@
subject

expect(response).to have_http_status(200)
expect(user.account.favourited?(status)).to be true

UnfavouriteWorker.drain
expect(user.account.favourited?(status)).to be false
end

Expand Down
2 changes: 1 addition & 1 deletion spec/requests/api/v1/timelines/home_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

describe 'Home' do
describe 'Home', :sidekiq_inline do
let(:user) { Fabricate(:user) }
let(:scopes) { 'read:statuses' }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

describe Account::StatusesSearch do
describe Account::StatusesSearch, :sidekiq_inline do
describe 'a non-indexable account becoming indexable' do
let(:account) { Account.find_by(username: 'search_test_account_1') }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
end
end

context 'with statuses referencing other statuses' do
context 'with statuses referencing other statuses', :sidekiq_inline do
before do
stub_const 'ActivityPub::FetchRemoteStatusService::DISCOVERIES_PER_REQUEST', 5
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/activitypub/process_account_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
end
end

it 'creates accounts without exceeding rate limit' do
it 'creates accounts without exceeding rate limit', :sidekiq_inline do
expect { subject.call('user1', 'foo.test', payload) }
.to create_some_remote_accounts
.and create_fewer_than_rate_limit_accounts
Expand Down
2 changes: 1 addition & 1 deletion spec/services/authorize_follow_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
expect(bob.following?(sender)).to be true
end

it 'sends an accept activity' do
it 'sends an accept activity', :sidekiq_inline do
expect(a_request(:post, bob.inbox_url)).to have_been_made.once
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/batched_remove_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

RSpec.describe BatchedRemoveStatusService, type: :service do
RSpec.describe BatchedRemoveStatusService, :sidekiq_inline, type: :service do
subject { described_class.new }

let!(:alice) { Fabricate(:account) }
Expand Down
2 changes: 1 addition & 1 deletion spec/services/block_domain_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
expect(already_banned_account.reload.silenced_at).to_not eq DomainBlock.find_by(domain: 'evil.org').created_at
end

it 'leaves the domains status and attachments, but clears media' do
it 'leaves the domains status and attachments, but clears media', :sidekiq_inline do
expect { bad_status_plain.reload }.to_not raise_error
expect { bad_status_with_attachment.reload }.to_not raise_error
expect { bad_attachment.reload }.to_not raise_error
Expand Down
2 changes: 1 addition & 1 deletion spec/services/block_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
expect(sender.blocking?(bob)).to be true
end

it 'sends a block activity' do
it 'sends a block activity', :sidekiq_inline do
expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/bulk_import_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import.update(total_items: import.rows.count)
end

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

describe '#call on local account' do
describe '#call on local account', :sidekiq_inline do
before do
stub_request(:post, remote_alice.inbox_url).to_return(status: 201)
stub_request(:post, remote_bob.inbox_url).to_return(status: 201)
Expand All @@ -83,7 +83,7 @@ def expect_deletion_of_associated_target_notifications
end
end

describe '#call on remote account' do
describe '#call on remote account', :sidekiq_inline do
before do
stub_request(:post, account.inbox_url).to_return(status: 201)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/fan_out_on_write_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

RSpec.describe FanOutOnWriteService, type: :service do
RSpec.describe FanOutOnWriteService, :sidekiq_inline, type: :service do
subject { described_class.new }

let(:last_active_at) { Time.now.utc }
Expand Down
2 changes: 1 addition & 1 deletion spec/services/favourite_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
expect(status.favourites.first).to_not be_nil
end

it 'sends a like activity' do
it 'sends a like activity', :sidekiq_inline do
expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/follow_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
expect(FollowRequest.find_by(account: sender, target_account: bob)).to_not be_nil
end

it 'sends a follow activity to the inbox' do
it 'sends a follow activity to the inbox', :sidekiq_inline do
expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/import_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

RSpec.describe ImportService, type: :service do
RSpec.describe ImportService, :sidekiq_inline, type: :service do
include RoutingHelper

let!(:account) { Fabricate(:account, locked: false) }
Expand Down
2 changes: 1 addition & 1 deletion spec/services/mute_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
redis.del(home_timeline_key)
end

it "clears account's statuses" do
it "clears account's statuses", :sidekiq_inline do
FeedManager.instance.push_to_home(account, status)
FeedManager.instance.push_to_home(account, other_account_status)

Expand Down

0 comments on commit 994a160

Please sign in to comment.