0
0
Fork 0

Fix RSpec/MessageSpies cop (#27751)

This commit is contained in:
Matt Jankowski 2023-11-07 04:46:28 -05:00 committed by GitHub
parent ae0d551d33
commit 49e2772064
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 162 additions and 94 deletions

View file

@ -36,8 +36,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
context 'when the payload is a Collection with inlined replies' do
context 'when passing the collection itself' do
it 'spawns workers for up to 5 replies on the same server' do
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
allow(FetchReplyWorker).to receive(:push_bulk)
subject.call(status, payload)
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
end
end
@ -47,8 +50,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
end
it 'spawns workers for up to 5 replies on the same server' do
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
allow(FetchReplyWorker).to receive(:push_bulk)
subject.call(status, collection_uri)
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
end
end
end
@ -65,8 +71,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
context 'when passing the collection itself' do
it 'spawns workers for up to 5 replies on the same server' do
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
allow(FetchReplyWorker).to receive(:push_bulk)
subject.call(status, payload)
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
end
end
@ -76,8 +85,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
end
it 'spawns workers for up to 5 replies on the same server' do
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
allow(FetchReplyWorker).to receive(:push_bulk)
subject.call(status, collection_uri)
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
end
end
end
@ -98,8 +110,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
context 'when passing the collection itself' do
it 'spawns workers for up to 5 replies on the same server' do
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
allow(FetchReplyWorker).to receive(:push_bulk)
subject.call(status, payload)
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
end
end
@ -109,8 +124,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
end
it 'spawns workers for up to 5 replies on the same server' do
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
allow(FetchReplyWorker).to receive(:push_bulk)
subject.call(status, collection_uri)
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
end
end
end

View file

@ -41,8 +41,11 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
end
it 'does not process payload' do
expect(ActivityPub::Activity).to_not receive(:factory)
allow(ActivityPub::Activity).to receive(:factory)
subject.call(json, actor)
expect(ActivityPub::Activity).to_not have_received(:factory)
end
end
end
@ -59,8 +62,11 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
end
it 'processes the payload' do
expect(ActivityPub::Activity).to receive(:factory)
allow(ActivityPub::Activity).to receive(:factory)
subject.call(json, actor)
expect(ActivityPub::Activity).to have_received(:factory)
end
end
end
@ -71,27 +77,33 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
it 'does not process payload if no signature exists' do
allow_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(nil)
expect(ActivityPub::Activity).to_not receive(:factory)
allow(ActivityPub::Activity).to receive(:factory)
subject.call(json, forwarder)
expect(ActivityPub::Activity).to_not have_received(:factory)
end
it 'processes payload with actor if valid signature exists' do
payload['signature'] = { 'type' => 'RsaSignature2017' }
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))
allow(ActivityPub::Activity).to receive(:factory).with(instance_of(Hash), actor, instance_of(Hash))
subject.call(json, forwarder)
expect(ActivityPub::Activity).to have_received(:factory).with(instance_of(Hash), actor, instance_of(Hash))
end
it 'does not process payload if invalid signature exists' do
payload['signature'] = { 'type' => 'RsaSignature2017' }
allow_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(nil)
expect(ActivityPub::Activity).to_not receive(:factory)
allow(ActivityPub::Activity).to receive(:factory)
subject.call(json, forwarder)
expect(ActivityPub::Activity).to_not have_received(:factory)
end
context 'when receiving a fabricated status' do
@ -225,7 +237,11 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
end
it 'does not process forged payload' do
expect(ActivityPub::Activity).to_not receive(:factory).with(
allow(ActivityPub::Activity).to receive(:factory)
subject.call(json, forwarder)
expect(ActivityPub::Activity).to_not have_received(:factory).with(
hash_including(
'object' => hash_including(
'id' => 'https://example.com/users/bob/fake-status'
@ -235,7 +251,7 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
anything
)
expect(ActivityPub::Activity).to_not receive(:factory).with(
expect(ActivityPub::Activity).to_not have_received(:factory).with(
hash_including(
'object' => hash_including(
'content' => '<p>puck was here</p>'
@ -245,8 +261,6 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
anything
)
subject.call(json, forwarder)
expect(Status.where(uri: 'https://example.com/users/bob/fake-status').exists?).to be false
end
end