mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-24 23:01:20 +00:00
Extract some contexts
This commit is contained in:
parent
9c04c0f0be
commit
03a17396e6
|
@ -20,21 +20,41 @@ RSpec.describe ActivityPub::FetchRepliesWorker do
|
|||
let(:json) { Oj.dump(payload) }
|
||||
|
||||
describe 'perform' do
|
||||
it 'performs a request if the collection URI is from the same host' do
|
||||
stub_request(:get, 'https://example.com/statuses_replies/1').to_return(status: 200, body: json, headers: { 'Content-Type': 'application/activity+json' })
|
||||
subject.perform(status.id, 'https://example.com/statuses_replies/1')
|
||||
expect(a_request(:get, 'https://example.com/statuses_replies/1')).to have_been_made.once
|
||||
context 'when the collection URI is from the same host' do
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/statuses_replies/1').to_return(status: 200, body: json, headers: { 'Content-Type': 'application/activity+json' })
|
||||
end
|
||||
|
||||
it 'performs a request' do
|
||||
subject.perform(status.id, 'https://example.com/statuses_replies/1')
|
||||
|
||||
expect(a_request(:get, 'https://example.com/statuses_replies/1'))
|
||||
.to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not perform a request if the collection URI is from a different host' do
|
||||
stub_request(:get, 'https://other.com/statuses_replies/1').to_return(status: 200)
|
||||
subject.perform(status.id, 'https://other.com/statuses_replies/1')
|
||||
expect(a_request(:get, 'https://other.com/statuses_replies/1')).to_not have_been_made
|
||||
context 'when the collection URI is from a different host' do
|
||||
before do
|
||||
stub_request(:get, 'https://other.com/statuses_replies/1').to_return(status: 200)
|
||||
end
|
||||
|
||||
it 'does not perform a request' do
|
||||
subject.perform(status.id, 'https://other.com/statuses_replies/1')
|
||||
|
||||
expect(a_request(:get, 'https://other.com/statuses_replies/1'))
|
||||
.to_not have_been_made
|
||||
end
|
||||
end
|
||||
|
||||
it 'raises when request fails' do
|
||||
stub_request(:get, 'https://example.com/statuses_replies/1').to_return(status: 500)
|
||||
expect { subject.perform(status.id, 'https://example.com/statuses_replies/1') }.to raise_error Mastodon::UnexpectedResponseError
|
||||
context 'when the request fails' do
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/statuses_replies/1').to_return(status: 500)
|
||||
end
|
||||
|
||||
it 'raises when request fails' do
|
||||
expect { subject.perform(status.id, 'https://example.com/statuses_replies/1') }
|
||||
.to raise_error Mastodon::UnexpectedResponseError
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,22 +11,28 @@ RSpec.describe PublishAnnouncementReactionWorker do
|
|||
let(:announcement) { Fabricate(:announcement) }
|
||||
let(:name) { 'name value' }
|
||||
|
||||
it 'sends the announcement and name to the service when subscribed' do
|
||||
allow(redis).to receive(:exists?).and_return(true)
|
||||
allow(redis).to receive(:publish)
|
||||
context 'when subscribed' do
|
||||
before { allow(redis).to receive(:exists?).and_return(true) }
|
||||
|
||||
worker.perform(announcement.id, name)
|
||||
it 'sends the announcement and name to the service' do
|
||||
allow(redis).to receive(:publish)
|
||||
|
||||
expect(redis).to have_received(:publish)
|
||||
worker.perform(announcement.id, name)
|
||||
|
||||
expect(redis).to have_received(:publish)
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not send the announcement and name to the service when not subscribed' do
|
||||
allow(redis).to receive(:exists?).and_return(false)
|
||||
allow(redis).to receive(:publish)
|
||||
context 'when not subscribed' do
|
||||
before { allow(redis).to receive(:exists?).and_return(false) }
|
||||
|
||||
worker.perform(announcement.id, name)
|
||||
it 'does not send the announcement and name to the service' do
|
||||
allow(redis).to receive(:publish)
|
||||
|
||||
expect(redis).to_not have_received(:publish)
|
||||
worker.perform(announcement.id, name)
|
||||
|
||||
expect(redis).to_not have_received(:publish)
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns true for non-existent record' do
|
||||
|
|
Loading…
Reference in a new issue