diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 213b518..c011d40 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-12-03 11:09:29 -0800 using RuboCop version 0.74.0. +# on 2019-12-03 15:41:39 -0800 using RuboCop version 0.74.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -8,4 +8,4 @@ # Offense count: 3 Metrics/AbcSize: - Max: 31 + Max: 34 diff --git a/README.md b/README.md index 36fd7d7..44d2582 100644 --- a/README.md +++ b/README.md @@ -51,13 +51,13 @@ Note that the preservation service is behind a firewall. - Preservation::Client.objects.current_version('oo000oo0000') (can also be 'druid:oo000oo0000') - Preservation::Client.objects.checksums(druids: druids) - will return raw csv - Preservation::Client.objects.checksums(druids: druids, format: 'json') - will return json -- Preservation::Client.objects.content('oo000oo0000', 'my_file.pdf') - will return contents of my_file.pdf in most recent version of Moab object -- Preservation::Client.objects.content('oo000oo0000', 'my_file.pdf', '1') - will return contents of my_file.pdf in version 1 of Moab object -- Preservation::Client.objects.manifest('oo000oo0000', 'versionInventory.xml') - will return contents of versionInventory.xml in most recent version of Moab object -- Preservation::Client.objects.manifest('oo000oo0000', 'versionInventory.xml', '3') - will return contents of versionInventory.xml in version 3 of Moab object -- Preservation::Client.objects.metadata('oo000oo0000', 'identityMetadata.xml') - will return contents of identityMetadata.xml in most recent version of Moab object -- Preservation::Client.objects.metadata('oo000oo0000', 'identityMetadata.xml', '8') - will return contents of identityMetadata.xml in version 8 of Moab object -- Preservation::Client.objects.signature_catalog('oo000oo0000') - will return contents of latest version of signatureCatalog.xml from Moab object +- Preservation::Client.objects.content(druid: 'oo000oo0000', filepath: 'my_file.pdf') - will return contents of my_file.pdf in most recent version of Moab object +- Preservation::Client.objects.content(druid: 'oo000oo0000', filepath: 'my_file.pdf', version: '1') - will return contents of my_file.pdf in version 1 of Moab object +- Preservation::Client.objects.manifest(druid: 'oo000oo0000', filepath: 'versionInventory.xml') - will return contents of versionInventory.xml in most recent version of Moab object +- Preservation::Client.objects.manifest(druid: 'oo000oo0000', filepath: 'versionInventory.xml', version: '3') - will return contents of versionInventory.xml in version 3 of Moab object +- Preservation::Client.objects.metadata(druid: 'oo000oo0000', filepath: 'identityMetadata.xml') - will return contents of identityMetadata.xml in most recent version of Moab object +- Preservation::Client.objects.metadata(druid: 'oo000oo0000', filepath: 'identityMetadata.xml', version: '8') - will return contents of identityMetadata.xml in version 8 of Moab object +- Preservation::Client.objects.signature_catalog(druid: 'oo000oo0000') - will return contents of latest version of signatureCatalog.xml from Moab object ## Development diff --git a/lib/preservation/client/objects.rb b/lib/preservation/client/objects.rb index 5357985..249ce3f 100644 --- a/lib/preservation/client/objects.rb +++ b/lib/preservation/client/objects.rb @@ -5,16 +5,16 @@ class Client # API calls that are about Preserved Objects class Objects < VersionedApiService # @param [Array] druids - required list of druids with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567' - # @param [String] :resp_format - desired format of the HTTP response (default csv, json also possible) + # @param [String] resp_format - desired format of the HTTP response (default csv, json also possible) # @return body of HTTP response from Preservation API - the checksums and filesize for each druid def checksums(druids: [], resp_format: 'csv') - post('objects/checksums', { druids: druids, format: resp_format }, 'checksums') + post('objects/checksums', druids: druids, format: resp_format) end # @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567' # @return [Integer] the current version of the Preserved Object def current_version(druid) - resp_body = get_json("objects/#{druid}.json", druid, 'current_version') + resp_body = get_json("objects/#{druid}.json", druid) resp_body[:current_version] end @@ -22,7 +22,7 @@ def current_version(druid) # @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567' # @param [String] filepath - the path of the file relative to the moab content directory # @param [String] version - the version of the file requested (defaults to nil for latest version) - def content(druid, filepath, version = nil) + def content(druid:, filepath:, version: nil) file(druid, 'content', filepath, version) end @@ -30,7 +30,7 @@ def content(druid, filepath, version = nil) # @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567' # @param [String] filepath - the path of the file relative to the moab manifest directory # @param [String] version - the version of the file requested (defaults to nil for latest version) - def manifest(druid, filepath, version = nil) + def manifest(druid:, filepath:, version: nil) file(druid, 'manifest', filepath, version) end @@ -38,14 +38,14 @@ def manifest(druid, filepath, version = nil) # @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567' # @param [String] filepath - the path of the file relative to the moab metadata directory # @param [String] version - the version of the file requested (defaults to nil for latest version) - def metadata(druid, filepath, version = nil) + def metadata(druid:, filepath:, version: nil) file(druid, 'metadata', filepath, version) end # convenience method for retrieving latest signatureCatalog.xml file from a Moab object # @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567' def signature_catalog(druid) - manifest(druid, 'signatureCatalog.xml') + manifest(druid: druid, filepath: 'signatureCatalog.xml') end private @@ -57,7 +57,7 @@ def signature_catalog(druid) # @param [String] version - the version of the file requested (defaults to nil for latest version) # @return the retrieved file def file(druid, category, filepath, version = nil) - get("objects/#{druid}/file", { category: category, filepath: filepath, version: version }, 'file') + get("objects/#{druid}/file", category: category, filepath: filepath, version: version) end end end diff --git a/lib/preservation/client/versioned_api_service.rb b/lib/preservation/client/versioned_api_service.rb index 9bd74b8..32411d2 100644 --- a/lib/preservation/client/versioned_api_service.rb +++ b/lib/preservation/client/versioned_api_service.rb @@ -14,7 +14,7 @@ def initialize(connection:, api_version:) attr_reader :connection, :api_version # @param path [String] path to be appended to connection url (no leading slash) - def get_json(path, object_id, caller_method_name) + def get_json(path, object_id) req_url = api_version.present? ? "#{api_version}/#{path}" : path resp = connection.get do |req| req.url req_url @@ -28,7 +28,7 @@ def get_json(path, object_id, caller_method_name) raise Preservation::Client::NotFoundError, errmsg else errmsg = ResponseErrorFormatter - .format(response: resp, object_id: object_id, client_method_name: caller_method_name) + .format(response: resp, object_id: object_id, client_method_name: caller_locations.first.label) raise Preservation::Client::UnexpectedResponseError, errmsg end rescue Faraday::ResourceNotFound => e @@ -41,13 +41,13 @@ def get_json(path, object_id, caller_method_name) # @param path [String] path to be appended to connection url (no leading slash) # @param params [Hash] optional params - def get(path, params, caller_method_name) + def get(path, params) get_path = api_version.present? ? "#{api_version}/#{path}" : path resp = connection.get get_path, params return resp.body if resp.success? errmsg = ResponseErrorFormatter - .format(response: resp, client_method_name: caller_method_name) + .format(response: resp, client_method_name: caller_locations.first.label) raise Preservation::Client::UnexpectedResponseError, errmsg rescue Faraday::ResourceNotFound => e errmsg = "HTTP GET to #{connection.url_prefix}#{path} failed with #{e.class}: #{e.message}" @@ -59,13 +59,13 @@ def get(path, params, caller_method_name) # @param path [String] path to be appended to connection url (no leading slash) # @param params [Hash] optional params - def post(path, params, caller_method_name) + def post(path, params) post_path = api_version.present? ? "#{api_version}/#{path}" : path resp = connection.post post_path, params return resp.body if resp.success? errmsg = ResponseErrorFormatter - .format(response: resp, client_method_name: caller_method_name) + .format(response: resp, client_method_name: caller_locations.first.label) raise Preservation::Client::UnexpectedResponseError, errmsg rescue Faraday::ResourceNotFound => e errmsg = "HTTP POST to #{connection.url_prefix}#{path} failed with #{e.class}: #{e.message}" diff --git a/spec/preservation/client/objects_spec.rb b/spec/preservation/client/objects_spec.rb index faa081b..5ecb08f 100644 --- a/spec/preservation/client/objects_spec.rb +++ b/spec/preservation/client/objects_spec.rb @@ -29,7 +29,7 @@ end before do - allow(subject).to receive(:get_json).with(path, druid, 'current_version').and_return(valid_response_body) + allow(subject).to receive(:get_json).with(path, druid).and_return(valid_response_body) end it 'returns the current version as an integer' do @@ -39,7 +39,7 @@ context 'when API request fails' do before do - allow(subject).to receive(:get_json).with(path, druid, 'current_version').and_raise(Preservation::Client::UnexpectedResponseError, err_msg) + allow(subject).to receive(:get_json).with(path, druid).and_raise(Preservation::Client::UnexpectedResponseError, err_msg) end it 'raises an error' do @@ -64,7 +64,7 @@ end before do - allow(subject).to receive(:post).with(path, params, 'checksums').and_return(valid_csv_response) + allow(subject).to receive(:post).with(path, params).and_return(valid_csv_response) end it 'returns the API response' do @@ -74,7 +74,7 @@ context 'when API request fails' do before do - allow(subject).to receive(:post).with(path, params, 'checksums').and_raise(Preservation::Client::UnexpectedResponseError, err_msg) + allow(subject).to receive(:post).with(path, params).and_raise(Preservation::Client::UnexpectedResponseError, err_msg) end it 'raises an error' do @@ -103,11 +103,11 @@ end before do - allow(subject).to receive(:get).with(file_api_path, file_api_params, 'file').and_return(valid_response_body) + allow(subject).to receive(:get).with(file_api_path, file_api_params).and_return(valid_response_body) end it 'returns the content file' do - expect(subject.content(file_druid, filename)).to eq valid_response_body + expect(subject.content(druid: file_druid, filepath: filename)).to eq valid_response_body end it 'returns the content file for specified version' do @@ -117,18 +117,18 @@ filepath: filename, version: '6' } - allow(subject).to receive(:get).with(file_api_path, my_file_api_params, 'file').and_return(valid_response_body) - expect(subject.content(file_druid, filename, '6')).to eq valid_response_body + allow(subject).to receive(:get).with(file_api_path, my_file_api_params).and_return(valid_response_body) + expect(subject.content(druid: file_druid, filepath: filename, version: '6')).to eq valid_response_body end end context 'when API request fails' do before do - allow(subject).to receive(:get).with(file_api_path, file_api_params, 'file').and_raise(Preservation::Client::UnexpectedResponseError, err_msg) + allow(subject).to receive(:get).with(file_api_path, file_api_params).and_raise(Preservation::Client::UnexpectedResponseError, err_msg) end it 'raises an error' do - expect { subject.content(file_druid, filename) }.to raise_error(Preservation::Client::UnexpectedResponseError, err_msg) + expect { subject.content(druid: file_druid, filepath: filename) }.to raise_error(Preservation::Client::UnexpectedResponseError, err_msg) end end end @@ -155,11 +155,11 @@ end before do - allow(subject).to receive(:get).with(file_api_path, file_api_params, 'file').and_return(valid_response_body) + allow(subject).to receive(:get).with(file_api_path, file_api_params).and_return(valid_response_body) end it 'returns the manifest file' do - expect(subject.manifest(file_druid, manifest_filename)).to eq valid_response_body + expect(subject.manifest(druid: file_druid, filepath: manifest_filename)).to eq valid_response_body end it 'returns the manifest file for specified version' do @@ -169,18 +169,18 @@ filepath: manifest_filename, version: '6' } - allow(subject).to receive(:get).with(file_api_path, my_file_api_params, 'file').and_return(valid_response_body) - expect(subject.manifest(file_druid, manifest_filename, '6')).to eq valid_response_body + allow(subject).to receive(:get).with(file_api_path, my_file_api_params).and_return(valid_response_body) + expect(subject.manifest(druid: file_druid, filepath: manifest_filename, version: '6')).to eq valid_response_body end end context 'when API request fails' do before do - allow(subject).to receive(:get).with(file_api_path, file_api_params, 'file').and_raise(Preservation::Client::UnexpectedResponseError, err_msg) + allow(subject).to receive(:get).with(file_api_path, file_api_params).and_raise(Preservation::Client::UnexpectedResponseError, err_msg) end it 'raises an error' do - expect { subject.manifest(file_druid, manifest_filename) }.to raise_error(Preservation::Client::UnexpectedResponseError, err_msg) + expect { subject.manifest(druid: file_druid, filepath: manifest_filename) }.to raise_error(Preservation::Client::UnexpectedResponseError, err_msg) end end end @@ -209,11 +209,11 @@ end before do - allow(subject).to receive(:get).with(file_api_path, file_api_params, 'file').and_return(valid_response_body) + allow(subject).to receive(:get).with(file_api_path, file_api_params).and_return(valid_response_body) end it 'returns the metadata file' do - expect(subject.metadata(file_druid, metadata_filename)).to eq valid_response_body + expect(subject.metadata(druid: file_druid, filepath: metadata_filename)).to eq valid_response_body end it 'returns the metadata file for specified version' do @@ -223,18 +223,18 @@ filepath: metadata_filename, version: '6' } - allow(subject).to receive(:get).with(file_api_path, my_file_api_params, 'file').and_return(valid_response_body) - expect(subject.metadata(file_druid, metadata_filename, '6')).to eq valid_response_body + allow(subject).to receive(:get).with(file_api_path, my_file_api_params).and_return(valid_response_body) + expect(subject.metadata(druid: file_druid, filepath: metadata_filename, version: '6')).to eq valid_response_body end end context 'when API request fails' do before do - allow(subject).to receive(:get).with(file_api_path, file_api_params, 'file').and_raise(Preservation::Client::UnexpectedResponseError, err_msg) + allow(subject).to receive(:get).with(file_api_path, file_api_params).and_raise(Preservation::Client::UnexpectedResponseError, err_msg) end it 'raises an error' do - expect { subject.metadata(file_druid, metadata_filename) }.to raise_error(Preservation::Client::UnexpectedResponseError, err_msg) + expect { subject.metadata(druid: file_druid, filepath: metadata_filename) }.to raise_error(Preservation::Client::UnexpectedResponseError, err_msg) end end end @@ -261,7 +261,7 @@ end before do - allow(subject).to receive(:get).with(file_api_path, file_api_params, 'file').and_return(valid_response_body) + allow(subject).to receive(:get).with(file_api_path, file_api_params).and_return(valid_response_body) end it 'returns the signature catalog file' do @@ -271,7 +271,7 @@ context 'when API request fails' do before do - allow(subject).to receive(:get).with(file_api_path, file_api_params, 'file').and_raise(Preservation::Client::UnexpectedResponseError, err_msg) + allow(subject).to receive(:get).with(file_api_path, file_api_params).and_raise(Preservation::Client::UnexpectedResponseError, err_msg) end it 'raises an error' do diff --git a/spec/preservation/client/versioned_api_service_spec.rb b/spec/preservation/client/versioned_api_service_spec.rb index b708561..61c4b93 100644 --- a/spec/preservation/client/versioned_api_service_spec.rb +++ b/spec/preservation/client/versioned_api_service_spec.rb @@ -3,7 +3,6 @@ RSpec.describe Preservation::Client::VersionedApiService do let(:prez_api_url) { 'https://prezcat.example.com' } let(:druid) { 'oo000oo0000' } - let(:caller_method_name) { 'my_method_name' } let(:faraday_err_msg) { 'faraday is sad' } before do @@ -27,13 +26,13 @@ it 'request url includes api_version when it is non-blank' do resp_body = JSON.generate(foo: 'have api version') stub_request(:get, "#{prez_api_url}/#{api_version}/#{path}").to_return(body: resp_body, status: 200) - expect(subject.send(:get_json, path, druid, caller_method_name)).to eq JSON.parse(resp_body) + expect(subject.send(:get_json, path, druid)).to eq JSON.parse(resp_body) end it 'request url has no api_version when it is blank' do pc = described_class.new(connection: conn, api_version: '') resp_body = JSON.generate(bar: 'blank api version') stub_request(:get, "#{prez_api_url}/#{path}").to_return(body: resp_body, status: 200) - expect(pc.send(:get_json, path, druid, caller_method_name)).to eq JSON.parse(resp_body) + expect(pc.send(:get_json, path, druid)).to eq JSON.parse(resp_body) end context 'when response status success' do @@ -41,7 +40,7 @@ it 'returns response body' do stub_request(:get, "#{prez_api_url}/#{api_version}/#{path}").to_return(body: resp_body, status: 200) - expect(subject.send(:get_json, path, druid, caller_method_name)).to eq JSON.parse(resp_body) + expect(subject.send(:get_json, path, druid)).to eq JSON.parse(resp_body) end end @@ -49,11 +48,11 @@ it '404 status code' do stub_request(:get, "#{prez_api_url}/#{api_version}/#{path}").to_return(status: 404) exp_msg = "#{druid} not found in Preservation at #{prez_api_url}/#{api_version}/#{path}" - expect { subject.send(:get_json, path, druid, caller_method_name) }.to raise_error(Preservation::Client::NotFoundError, exp_msg) + expect { subject.send(:get_json, path, druid) }.to raise_error(Preservation::Client::NotFoundError, exp_msg) end it 'raises Preservation::Client::UnexpectedResponseError with message from ResponseErrorFormatter' do stub_request(:get, "#{prez_api_url}/#{api_version}/#{path}").to_return(status: 500) - expect { subject.send(:get_json, path, druid, caller_method_name) }.to raise_error(Preservation::Client::UnexpectedResponseError, /got 500/) + expect { subject.send(:get_json, path, druid) }.to raise_error(Preservation::Client::UnexpectedResponseError, /got 500/) end end @@ -61,7 +60,7 @@ it 'raises Preservation::Client::NotFoundError' do allow(conn).to receive(:get).and_raise(Faraday::ResourceNotFound, faraday_err_msg) exp_err_msg = "HTTP GET to #{prez_api_url}/#{api_version}/#{path} failed with #{Faraday::ResourceNotFound}: #{faraday_err_msg}" - expect { subject.send(:get_json, path, druid, caller_method_name) }.to raise_error(Preservation::Client::NotFoundError, exp_err_msg) + expect { subject.send(:get_json, path, druid) }.to raise_error(Preservation::Client::NotFoundError, exp_err_msg) end end @@ -69,7 +68,7 @@ it 'raises Preservation::Client::UnexpectedResponseError' do allow(conn).to receive(:get).and_raise(Faraday::ParsingError, faraday_err_msg) exp_err_msg = "HTTP GET to #{prez_api_url}/#{api_version}/#{path} failed with #{Faraday::ParsingError}: #{faraday_err_msg}" - expect { subject.send(:get_json, path, druid, caller_method_name) }.to raise_error(Preservation::Client::UnexpectedResponseError, exp_err_msg) + expect { subject.send(:get_json, path, druid) }.to raise_error(Preservation::Client::UnexpectedResponseError, exp_err_msg) end end @@ -77,7 +76,7 @@ it 'raises Preservation::Client::UnexpectedResponseError' do allow(conn).to receive(:get).and_raise(Faraday::RetriableResponse, faraday_err_msg) exp_err_msg = "HTTP GET to #{prez_api_url}/#{api_version}/#{path} failed with #{Faraday::RetriableResponse}: #{faraday_err_msg}" - expect { subject.send(:get_json, path, druid, caller_method_name) }.to raise_error(Preservation::Client::UnexpectedResponseError, exp_err_msg) + expect { subject.send(:get_json, path, druid) }.to raise_error(Preservation::Client::UnexpectedResponseError, exp_err_msg) end end end @@ -91,12 +90,12 @@ it 'request url includes api_version when it is non-blank' do stub_request(:get, "#{prez_api_url}/#{api_version}/#{path}?#{params_as_args}") .to_return(body: 'have api version', status: 200) - expect(subject.send(:get, path, params, caller_method_name)).to eq 'have api version' + expect(subject.send(:get, path, params)).to eq 'have api version' end it 'request url has no api_version when it is blank' do pc = described_class.new(connection: conn, api_version: '') stub_request(:get, "#{prez_api_url}/#{path}?#{params_as_args}").to_return(body: 'blank api version', status: 200) - expect(pc.send(:get, path, params, caller_method_name)).to eq 'blank api version' + expect(pc.send(:get, path, params)).to eq 'blank api version' end context 'when response status success' do @@ -105,14 +104,14 @@ it 'returns response body' do stub_request(:get, "#{prez_api_url}/#{api_version}/#{path}?#{params_as_args}") .to_return(body: resp_body, status: 200) - expect(subject.send(:get, path, params, caller_method_name)).to eq resp_body + expect(subject.send(:get, path, params)).to eq resp_body end end context 'when response status NOT success' do it 'raises Preservation::Client::UnexpectedResponseError with message from ResponseErrorFormatter' do stub_request(:get, "#{prez_api_url}/#{api_version}/#{path}?#{params_as_args}").to_return(status: 500) - expect { subject.send(:get, path, params, caller_method_name) }.to raise_error(Preservation::Client::UnexpectedResponseError, /got 500/) + expect { subject.send(:get, path, params) }.to raise_error(Preservation::Client::UnexpectedResponseError, /got 500/) end end @@ -120,7 +119,7 @@ it 'raises Preservation::Client::NotFoundError' do allow(conn).to receive(:get).and_raise(Faraday::ResourceNotFound, faraday_err_msg) exp_err_msg = "HTTP GET to #{prez_api_url}/#{path} failed with #{Faraday::ResourceNotFound}: #{faraday_err_msg}" - expect { subject.send(:get, path, params, caller_method_name) }.to raise_error(Preservation::Client::NotFoundError, exp_err_msg) + expect { subject.send(:get, path, params) }.to raise_error(Preservation::Client::NotFoundError, exp_err_msg) end end @@ -128,7 +127,7 @@ it 'raises Preservation::Client::UnexpectedResponseError' do allow(conn).to receive(:get).and_raise(Faraday::ParsingError, faraday_err_msg) exp_err_msg = "HTTP GET to #{prez_api_url}/#{path} failed with #{Faraday::ParsingError}: #{faraday_err_msg}" - expect { subject.send(:get, path, params, caller_method_name) }.to raise_error(Preservation::Client::UnexpectedResponseError, exp_err_msg) + expect { subject.send(:get, path, params) }.to raise_error(Preservation::Client::UnexpectedResponseError, exp_err_msg) end end @@ -136,7 +135,7 @@ it 'raises Preservation::Client::UnexpectedResponseError' do allow(conn).to receive(:get).and_raise(Faraday::RetriableResponse, faraday_err_msg) exp_err_msg = "HTTP GET to #{prez_api_url}/#{path} failed with #{Faraday::RetriableResponse}: #{faraday_err_msg}" - expect { subject.send(:get, path, params, caller_method_name) }.to raise_error(Preservation::Client::UnexpectedResponseError, exp_err_msg) + expect { subject.send(:get, path, params) }.to raise_error(Preservation::Client::UnexpectedResponseError, exp_err_msg) end end end @@ -149,12 +148,12 @@ it 'request url includes api_version when it is non-blank' do stub_request(:post, "#{prez_api_url}/#{api_version}/#{path}").to_return(body: 'have api version', status: 200) - expect(subject.send(:post, path, params, caller_method_name)).to eq 'have api version' + expect(subject.send(:post, path, params)).to eq 'have api version' end it 'request url has no api_version when it is blank' do pc = described_class.new(connection: conn, api_version: '') stub_request(:post, "#{prez_api_url}/#{path}").to_return(body: 'blank api version', status: 200) - expect(pc.send(:post, path, params, caller_method_name)).to eq 'blank api version' + expect(pc.send(:post, path, params)).to eq 'blank api version' end context 'when response status success' do @@ -162,14 +161,14 @@ it 'returns response body' do stub_request(:post, "#{prez_api_url}/#{api_version}/#{path}").to_return(body: resp_body, status: 200) - expect(subject.send(:post, path, params, caller_method_name)).to eq resp_body + expect(subject.send(:post, path, params)).to eq resp_body end end context 'when response status NOT success' do it 'raises Preservation::Client::UnexpectedResponseError with message from ResponseErrorFormatter' do stub_request(:post, "#{prez_api_url}/#{api_version}/#{path}").to_return(status: 500) - expect { subject.send(:post, path, params, caller_method_name) }.to raise_error(Preservation::Client::UnexpectedResponseError, /got 500/) + expect { subject.send(:post, path, params) }.to raise_error(Preservation::Client::UnexpectedResponseError, /got 500/) end end @@ -177,7 +176,7 @@ it 'raises Preservation::Client::NotFoundError' do allow(conn).to receive(:post).and_raise(Faraday::ResourceNotFound, faraday_err_msg) exp_err_msg = "HTTP POST to #{prez_api_url}/#{path} failed with #{Faraday::ResourceNotFound}: #{faraday_err_msg}" - expect { subject.send(:post, path, params, caller_method_name) }.to raise_error(Preservation::Client::NotFoundError, exp_err_msg) + expect { subject.send(:post, path, params) }.to raise_error(Preservation::Client::NotFoundError, exp_err_msg) end end @@ -185,7 +184,7 @@ it 'raises Preservation::Client::UnexpectedResponseError' do allow(conn).to receive(:post).and_raise(Faraday::ParsingError, faraday_err_msg) exp_err_msg = "HTTP POST to #{prez_api_url}/#{path} failed with #{Faraday::ParsingError}: #{faraday_err_msg}" - expect { subject.send(:post, path, params, caller_method_name) }.to raise_error(Preservation::Client::UnexpectedResponseError, exp_err_msg) + expect { subject.send(:post, path, params) }.to raise_error(Preservation::Client::UnexpectedResponseError, exp_err_msg) end end @@ -193,7 +192,7 @@ it 'raises Preservation::Client::UnexpectedResponseError' do allow(conn).to receive(:post).and_raise(Faraday::RetriableResponse, faraday_err_msg) exp_err_msg = "HTTP POST to #{prez_api_url}/#{path} failed with #{Faraday::RetriableResponse}: #{faraday_err_msg}" - expect { subject.send(:post, path, params, caller_method_name) }.to raise_error(Preservation::Client::UnexpectedResponseError, exp_err_msg) + expect { subject.send(:post, path, params) }.to raise_error(Preservation::Client::UnexpectedResponseError, exp_err_msg) end end end