Prefer rspec-sidekiq matchers over "expect push bulk to match" approach (#38274)

This commit is contained in:
Matt Jankowski 2026-03-18 09:21:54 -04:00 committed by GitHub
parent e537292e2a
commit bd9b24f1ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 32 additions and 39 deletions

View File

@ -44,12 +44,3 @@ def serialized_record_json(record, serializer, adapter: nil, options: {})
).to_json
)
end
def expect_push_bulk_to_match(klass, matcher)
allow(Sidekiq::Client).to receive(:push_bulk)
yield
expect(Sidekiq::Client).to have_received(:push_bulk).with(hash_including({
'class' => klass,
'args' => matcher,
}))
end

View File

@ -16,9 +16,10 @@ RSpec.describe ActivityPub::DistributePollUpdateWorker do
end
it 'delivers to followers' do
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(type: 'Update'), account.id, 'http://example.com']]) do
subject.perform(status.id)
end
expect(ActivityPub::DeliveryWorker)
.to have_enqueued_sidekiq_job(match_json_values(type: 'Update'), account.id, 'http://example.com')
end
end
end

View File

@ -19,9 +19,10 @@ RSpec.describe ActivityPub::DistributionWorker do
end
it 'delivers to followers' do
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(type: 'Create'), status.account.id, 'http://example.com', anything]]) do
subject.perform(status.id)
end
expect(ActivityPub::DeliveryWorker)
.to have_enqueued_sidekiq_job(match_json_values(type: 'Create'), status.account.id, 'http://example.com', anything)
end
end
@ -31,9 +32,10 @@ RSpec.describe ActivityPub::DistributionWorker do
end
it 'delivers to followers' do
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(type: 'Create'), status.account.id, 'http://example.com', anything]]) do
subject.perform(status.id)
end
expect(ActivityPub::DeliveryWorker)
.to have_enqueued_sidekiq_job(match_json_values(type: 'Create'), status.account.id, 'http://example.com', anything)
end
end
@ -46,9 +48,10 @@ RSpec.describe ActivityPub::DistributionWorker do
end
it 'delivers to mentioned accounts' do
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(type: 'Create'), status.account.id, 'https://foo.bar/inbox', anything]]) do
subject.perform(status.id)
end
expect(ActivityPub::DeliveryWorker)
.to have_enqueued_sidekiq_job(match_json_values(type: 'Create'), status.account.id, 'https://foo.bar/inbox', anything)
end
end
@ -67,9 +70,10 @@ RSpec.describe ActivityPub::DistributionWorker do
object: ActivityPub::TagManager.instance.uri_for(status),
}
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(expected_json), reblog.account.id, 'http://example.com', anything]]) do
subject.perform(reblog.id)
end
expect(ActivityPub::DeliveryWorker)
.to have_enqueued_sidekiq_job(match_json_values(expected_json), reblog.account.id, 'http://example.com', anything)
end
end
@ -86,9 +90,10 @@ RSpec.describe ActivityPub::DistributionWorker do
}),
}
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(expected_json), reblog.account.id, 'http://example.com', anything]]) do
subject.perform(reblog.id)
end
expect(ActivityPub::DeliveryWorker)
.to have_enqueued_sidekiq_job(match_json_values(expected_json), reblog.account.id, 'http://example.com', anything)
end
end
end

View File

@ -16,16 +16,11 @@ RSpec.describe ActivityPub::MoveDistributionWorker do
end
it 'delivers to followers and known blockers' do
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, expected_migration_deliveries) do
subject.perform(migration.id)
end
end
def expected_migration_deliveries
[
[match_json_values(type: 'Move'), migration.account.id, 'http://example.com'],
[match_json_values(type: 'Move'), migration.account.id, 'http://example2.com'],
]
expect(ActivityPub::DeliveryWorker)
.to have_enqueued_sidekiq_job(match_json_values(type: 'Move'), migration.account.id, 'http://example.com')
.and have_enqueued_sidekiq_job(match_json_values(type: 'Move'), migration.account.id, 'http://example2.com')
end
end
end

View File

@ -14,9 +14,10 @@ RSpec.describe ActivityPub::UpdateDistributionWorker do
end
it 'delivers to followers' do
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(type: 'Update'), account.id, 'http://example.com', anything]]) do
subject.perform(account.id)
end
expect(ActivityPub::DeliveryWorker)
.to have_enqueued_sidekiq_job(match_json_values(type: 'Update'), account.id, 'http://example.com', anything)
end
end
end