diff options
author | Jenkins <jenkins@jenkins.ninjawedding.org> | 2018-02-08 23:17:14 +0000 |
---|---|---|
committer | Jenkins <jenkins@jenkins.ninjawedding.org> | 2018-02-08 23:17:14 +0000 |
commit | 5ba2c300d8ab0e3adc58a380162b66abafbb3bb8 (patch) | |
tree | a3bb67479db79ca9777cf2d6c1b767ad0f0f53d2 /spec | |
parent | 3405ea6dd9fde38ba1044933fec2ec7fa909ea8c (diff) | |
parent | 1167c6dbf8d5b8411d9924350b2b9735da6d9d26 (diff) |
Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/api/salmon_controller_spec.rb | 16 | ||||
-rw-r--r-- | spec/services/fetch_atom_service_spec.rb | 59 |
2 files changed, 74 insertions, 1 deletions
diff --git a/spec/controllers/api/salmon_controller_spec.rb b/spec/controllers/api/salmon_controller_spec.rb index 323d85b61..8af8b83a8 100644 --- a/spec/controllers/api/salmon_controller_spec.rb +++ b/spec/controllers/api/salmon_controller_spec.rb @@ -40,7 +40,7 @@ RSpec.describe Api::SalmonController, type: :controller do end end - context 'with invalid post data' do + context 'with empty post data' do before do request.env['RAW_POST_DATA'] = '' post :update, params: { id: account.id } @@ -50,5 +50,19 @@ RSpec.describe Api::SalmonController, type: :controller do expect(response).to have_http_status(400) end end + + context 'with invalid post data' do + before do + service = double(call: false) + allow(VerifySalmonService).to receive(:new).and_return(service) + + request.env['RAW_POST_DATA'] = File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml')) + post :update, params: { id: account.id } + end + + it 'returns http client error' do + expect(response).to have_http_status(401) + end + end end end diff --git a/spec/services/fetch_atom_service_spec.rb b/spec/services/fetch_atom_service_spec.rb index 5491fd027..d7f162b85 100644 --- a/spec/services/fetch_atom_service_spec.rb +++ b/spec/services/fetch_atom_service_spec.rb @@ -1,4 +1,63 @@ require 'rails_helper' RSpec.describe FetchAtomService do + describe '#link_header' do + context 'Link is Array' do + target = FetchAtomService.new + target.instance_variable_set('@response', 'Link' => [ + '<http://example.com/>; rel="up"; meta="bar"', + '<http://example.com/foo>; rel="self"', + ]) + + it 'set first link as link_header' do + expect(target.send(:link_header).links[0].href).to eq 'http://example.com/' + end + end + + context 'Link is not Array' do + target = FetchAtomService.new + target.instance_variable_set('@response', 'Link' => '<http://example.com/foo>; rel="self", <http://example.com/>; rel = "up"') + + it { expect(target.send(:link_header).links[0].href).to eq 'http://example.com/foo' } + end + end + + describe '#perform_request' do + let(:url) { 'http://example.com' } + context 'Check method result' do + before do + WebMock.stub_request(:get, url).to_return(status: 200, body: '', headers: {}) + @target = FetchAtomService.new + @target.instance_variable_set('@url', url) + end + + it 'HTTP::Response instance is returned and set to @response' do + expect(@target.send(:perform_request).status.to_s).to eq '200 OK' + expect(@target.instance_variable_get('@response')).to be_instance_of HTTP::Response + end + end + + context 'check passed parameters to Request' do + before do + @target = FetchAtomService.new + @target.instance_variable_set('@url', url) + @target.instance_variable_set('@unsupported_activity', unsupported_activity) + allow(Request).to receive(:new).with(:get, url) + expect(Request).to receive_message_chain(:new, :add_headers).with('Accept' => accept) + allow(Request).to receive_message_chain(:new, :add_headers, :perform).with(no_args) + end + + context '@unsupported_activity is true' do + let(:unsupported_activity) { true } + let(:accept) { 'text/html' } + it { @target.send(:perform_request) } + end + + context '@unsupported_activity is false' do + let(:unsupported_activity) { false } + let(:accept) { 'application/activity+json, application/ld+json, application/atom+xml, text/html' } + it { @target.send(:perform_request) } + end + end + end end |