diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2019-07-10 18:59:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-10 18:59:28 +0200 |
commit | 5d3feed191bcbe2769512119752b426108152fe9 (patch) | |
tree | b36bc69823e5a16250bb9f72d388498737d6725a /spec | |
parent | d04c584159fdad36d7713718c4ba0b3b42cd27a9 (diff) |
Refactor fetching of remote resources (#11251)
Diffstat (limited to 'spec')
-rw-r--r-- | spec/services/fetch_remote_account_service_spec.rb | 1 | ||||
-rw-r--r-- | spec/services/fetch_resource_service_spec.rb (renamed from spec/services/fetch_atom_service_spec.rb) | 14 | ||||
-rw-r--r-- | spec/services/resolve_url_service_spec.rb | 44 |
3 files changed, 13 insertions, 46 deletions
diff --git a/spec/services/fetch_remote_account_service_spec.rb b/spec/services/fetch_remote_account_service_spec.rb index 37e9910d4..ee7325be2 100644 --- a/spec/services/fetch_remote_account_service_spec.rb +++ b/spec/services/fetch_remote_account_service_spec.rb @@ -4,6 +4,7 @@ RSpec.describe FetchRemoteAccountService, type: :service do let(:url) { 'https://example.com/alice' } let(:prefetched_body) { nil } let(:protocol) { :ostatus } + subject { FetchRemoteAccountService.new.call(url, prefetched_body, protocol) } let(:actor) do diff --git a/spec/services/fetch_atom_service_spec.rb b/spec/services/fetch_resource_service_spec.rb index 495540004..17c192c44 100644 --- a/spec/services/fetch_atom_service_spec.rb +++ b/spec/services/fetch_resource_service_spec.rb @@ -1,9 +1,11 @@ require 'rails_helper' -RSpec.describe FetchAtomService, type: :service do +RSpec.describe FetchResourceService, type: :service do + let!(:representative) { Fabricate(:account) } + describe '#call' do let(:url) { 'http://example.com' } - subject { FetchAtomService.new.call(url) } + subject { described_class.new.call(url) } context 'url is blank' do let(:url) { '' } @@ -23,8 +25,7 @@ RSpec.describe FetchAtomService, type: :service do allow(Request).to receive_message_chain(:new, :add_headers, :perform).and_raise(OpenSSL::SSL::SSLError) end - it 'output log and return nil' do - expect_any_instance_of(ActiveSupport::Logger).to receive(:debug).with('SSL error: OpenSSL::SSL::SSLError') + it 'return nil' do is_expected.to be_nil end end @@ -34,8 +35,7 @@ RSpec.describe FetchAtomService, type: :service do allow(Request).to receive_message_chain(:new, :add_headers, :perform).and_raise(HTTP::ConnectionError) end - it 'output log and return nil' do - expect_any_instance_of(ActiveSupport::Logger).to receive(:debug).with('HTTP ConnectionError: HTTP::ConnectionError') + it 'return nil' do is_expected.to be_nil end end @@ -57,7 +57,7 @@ RSpec.describe FetchAtomService, type: :service do context 'content type is application/atom+xml' do let(:content_type) { 'application/atom+xml' } - it { is_expected.to eq [url, { :prefetched_body => "" }, :ostatus] } + it { is_expected.to eq nil } end context 'content_type is activity+json' do diff --git a/spec/services/resolve_url_service_spec.rb b/spec/services/resolve_url_service_spec.rb index 7bb5d1940..aa4204637 100644 --- a/spec/services/resolve_url_service_spec.rb +++ b/spec/services/resolve_url_service_spec.rb @@ -6,48 +6,14 @@ describe ResolveURLService, type: :service do subject { described_class.new } describe '#call' do - it 'returns nil when there is no atom url' do - url = 'http://example.com/missing-atom' + it 'returns nil when there is no resource url' do + url = 'http://example.com/missing-resource' service = double - allow(FetchAtomService).to receive(:new).and_return service - allow(service).to receive(:call).with(url).and_return(nil) - - result = subject.call(url) - expect(result).to be_nil - end - - it 'fetches remote accounts for feed types' do - url = 'http://example.com/atom-feed' - service = double - allow(FetchAtomService).to receive(:new).and_return service - feed_url = 'http://feed-url' - feed_content = '<feed>contents</feed>' - allow(service).to receive(:call).with(url).and_return([feed_url, { prefetched_body: feed_content }]) - - account_service = double - allow(FetchRemoteAccountService).to receive(:new).and_return(account_service) - allow(account_service).to receive(:call) - - _result = subject.call(url) - expect(account_service).to have_received(:call).with(feed_url, feed_content, nil) - end - - it 'fetches remote statuses for entry types' do - url = 'http://example.com/atom-entry' - service = double - allow(FetchAtomService).to receive(:new).and_return service - feed_url = 'http://feed-url' - feed_content = '<entry>contents</entry>' - allow(service).to receive(:call).with(url).and_return([feed_url, { prefetched_body: feed_content }]) - - account_service = double - allow(FetchRemoteStatusService).to receive(:new).and_return(account_service) - allow(account_service).to receive(:call) - - _result = subject.call(url) + allow(FetchResourceService).to receive(:new).and_return service + allow(service).to receive(:call).with(url).and_return(nil) - expect(account_service).to have_received(:call).with(feed_url, feed_content, nil) + expect(subject.call(url)).to be_nil end end end |