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) }
|
let(:json) { Oj.dump(payload) }
|
||||||
|
|
||||||
describe 'perform' do
|
describe 'perform' do
|
||||||
it 'performs a request if the collection URI is from the same host' do
|
context 'when 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' })
|
before do
|
||||||
subject.perform(status.id, 'https://example.com/statuses_replies/1')
|
stub_request(:get, 'https://example.com/statuses_replies/1').to_return(status: 200, body: json, headers: { 'Content-Type': 'application/activity+json' })
|
||||||
expect(a_request(:get, 'https://example.com/statuses_replies/1')).to have_been_made.once
|
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
|
end
|
||||||
|
|
||||||
it 'does not perform a request if the collection URI is from a different host' do
|
context 'when the collection URI is from a different host' do
|
||||||
stub_request(:get, 'https://other.com/statuses_replies/1').to_return(status: 200)
|
before do
|
||||||
subject.perform(status.id, 'https://other.com/statuses_replies/1')
|
stub_request(:get, 'https://other.com/statuses_replies/1').to_return(status: 200)
|
||||||
expect(a_request(:get, 'https://other.com/statuses_replies/1')).to_not have_been_made
|
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
|
end
|
||||||
|
|
||||||
it 'raises when request fails' do
|
context 'when the request fails' do
|
||||||
stub_request(:get, 'https://example.com/statuses_replies/1').to_return(status: 500)
|
before do
|
||||||
expect { subject.perform(status.id, 'https://example.com/statuses_replies/1') }.to raise_error Mastodon::UnexpectedResponseError
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,22 +11,28 @@ RSpec.describe PublishAnnouncementReactionWorker do
|
||||||
let(:announcement) { Fabricate(:announcement) }
|
let(:announcement) { Fabricate(:announcement) }
|
||||||
let(:name) { 'name value' }
|
let(:name) { 'name value' }
|
||||||
|
|
||||||
it 'sends the announcement and name to the service when subscribed' do
|
context 'when subscribed' do
|
||||||
allow(redis).to receive(:exists?).and_return(true)
|
before { allow(redis).to receive(:exists?).and_return(true) }
|
||||||
allow(redis).to receive(:publish)
|
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
||||||
it 'does not send the announcement and name to the service when not subscribed' do
|
context 'when not subscribed' do
|
||||||
allow(redis).to receive(:exists?).and_return(false)
|
before { allow(redis).to receive(:exists?).and_return(false) }
|
||||||
allow(redis).to receive(:publish)
|
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
||||||
it 'returns true for non-existent record' do
|
it 'returns true for non-existent record' do
|
||||||
|
|
Loading…
Reference in a new issue