From 3060341ff996419a7fb04b3211b011a9478d58cc Mon Sep 17 00:00:00 2001 From: Peter Cai <222655+pcai@users.noreply.github.com> Date: Sat, 1 Oct 2022 05:16:47 +0000 Subject: [PATCH 1/3] rename Savon::Response#hash to Savon::Response#response_hash --- lib/savon/response.rb | 4 ++-- spec/savon/options_spec.rb | 6 +++--- spec/savon/response_spec.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/savon/response.rb b/lib/savon/response.rb index 2e7a1bea..45851a38 100644 --- a/lib/savon/response.rb +++ b/lib/savon/response.rb @@ -54,7 +54,7 @@ def to_array(*path) result.kind_of?(Array) ? result.compact : [result].compact end - def hash + def response_hash @hash ||= nori.parse(xml) end @@ -79,7 +79,7 @@ def xpath(path, namespaces = nil) end def find(*path) - envelope = nori.find(hash, 'Envelope') + envelope = nori.find(response_hash, 'Envelope') raise_invalid_response_error! unless envelope.is_a?(Hash) nori.find(envelope, *path) diff --git a/spec/savon/options_spec.rb b/spec/savon/options_spec.rb index 34908971..68b0307c 100644 --- a/spec/savon/options_spec.rb +++ b/spec/savon/options_spec.rb @@ -850,7 +850,7 @@ def to_s response = client.call(:authenticate, :xml => Fixture.response(:authentication)) - expect(response.hash["soap:envelope"]["soap:body"]).to include("ns2:authenticate_response") + expect(response.response_hash["soap:envelope"]["soap:body"]).to include("ns2:authenticate_response") end end @@ -880,7 +880,7 @@ def to_s client = new_client(:endpoint => @server.url(:repeat), :convert_response_tags_to => lambda { |tag| tag.snakecase.upcase }) response = client.call(:authenticate, :xml => Fixture.response(:authentication)) - expect(response.hash["ENVELOPE"]["BODY"]).to include("AUTHENTICATE_RESPONSE") + expect(response.response_hash["ENVELOPE"]["BODY"]).to include("AUTHENTICATE_RESPONSE") end it "accepts a block in the block-based interface" do @@ -895,7 +895,7 @@ def to_s locals.xml Fixture.response(:authentication) end - expect(response.hash["ENVELOPE"]["BODY"]).to include("AUTHENTICATE_RESPONSE") + expect(response.response_hash["ENVELOPE"]["BODY"]).to include("AUTHENTICATE_RESPONSE") end end diff --git a/spec/savon/response_spec.rb b/spec/savon/response_spec.rb index c5466b7d..c802779d 100644 --- a/spec/savon/response_spec.rb +++ b/spec/savon/response_spec.rb @@ -206,7 +206,7 @@ describe "#hash" do it "should return the complete SOAP response XML as a Hash" do response = soap_response :body => Fixture.response(:header) - expect(response.hash[:envelope][:header][:session_number]).to eq("ABCD1234") + expect(response.response_hash[:envelope][:header][:session_number]).to eq("ABCD1234") end end From 766d6b119af30b624e7f58f9ac04d13d46bb305e Mon Sep 17 00:00:00 2001 From: Peter Cai <222655+pcai@users.noreply.github.com> Date: Tue, 18 Oct 2022 18:30:13 -0400 Subject: [PATCH 2/3] match name of method when memoizing Co-authored-by: Olle Jonsson --- lib/savon/response.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/savon/response.rb b/lib/savon/response.rb index 45851a38..525cded8 100644 --- a/lib/savon/response.rb +++ b/lib/savon/response.rb @@ -55,7 +55,7 @@ def to_array(*path) end def response_hash - @hash ||= nori.parse(xml) + @response_hash ||= nori.parse(xml) end def xml From 68556dc110d8b3cb7bbf1c097eaa2d06718baabb Mon Sep 17 00:00:00 2001 From: Peter Cai <222655+pcai@users.noreply.github.com> Date: Wed, 19 Oct 2022 04:03:20 +0000 Subject: [PATCH 3/3] rename to full_hash, fix tests so they pass in both rack 2 and rack 3 --- lib/savon/response.rb | 6 +++--- spec/savon/mock_spec.rb | 2 +- spec/savon/options_spec.rb | 8 ++++---- spec/savon/response_spec.rb | 6 +++--- spec/support/fixture.rb | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/savon/response.rb b/lib/savon/response.rb index 525cded8..9ca4a35b 100644 --- a/lib/savon/response.rb +++ b/lib/savon/response.rb @@ -54,8 +54,8 @@ def to_array(*path) result.kind_of?(Array) ? result.compact : [result].compact end - def response_hash - @response_hash ||= nori.parse(xml) + def full_hash + @full_hash ||= nori.parse(xml) end def xml @@ -79,7 +79,7 @@ def xpath(path, namespaces = nil) end def find(*path) - envelope = nori.find(response_hash, 'Envelope') + envelope = nori.find(full_hash, 'Envelope') raise_invalid_response_error! unless envelope.is_a?(Hash) nori.find(envelope, *path) diff --git a/spec/savon/mock_spec.rb b/spec/savon/mock_spec.rb index 8f3b9620..d9becd63 100644 --- a/spec/savon/mock_spec.rb +++ b/spec/savon/mock_spec.rb @@ -37,7 +37,7 @@ it "accepts a Hash to specify the response code, headers and body" do soap_fault = Fixture.response(:soap_fault) - response = { :code => 500, :headers => { "X-Result" => "invalid" }, :body => soap_fault } + response = { :code => 500, :headers => { "x-result" => "invalid" }, :body => soap_fault } savon.expects(:authenticate).returns(response) response = new_client(:raise_errors => false).call(:authenticate) diff --git a/spec/savon/options_spec.rb b/spec/savon/options_spec.rb index 68b0307c..247df12e 100644 --- a/spec/savon/options_spec.rb +++ b/spec/savon/options_spec.rb @@ -405,7 +405,7 @@ def to_s client = new_client(:endpoint => @server.url, :log => true) client.call(:authenticate) } - soap_header = stdout.string.include? "content-type" + soap_header = stdout.string.downcase.include? "content-type" expect(soap_header).to be true end @@ -850,7 +850,7 @@ def to_s response = client.call(:authenticate, :xml => Fixture.response(:authentication)) - expect(response.response_hash["soap:envelope"]["soap:body"]).to include("ns2:authenticate_response") + expect(response.full_hash["soap:envelope"]["soap:body"]).to include("ns2:authenticate_response") end end @@ -880,7 +880,7 @@ def to_s client = new_client(:endpoint => @server.url(:repeat), :convert_response_tags_to => lambda { |tag| tag.snakecase.upcase }) response = client.call(:authenticate, :xml => Fixture.response(:authentication)) - expect(response.response_hash["ENVELOPE"]["BODY"]).to include("AUTHENTICATE_RESPONSE") + expect(response.full_hash["ENVELOPE"]["BODY"]).to include("AUTHENTICATE_RESPONSE") end it "accepts a block in the block-based interface" do @@ -895,7 +895,7 @@ def to_s locals.xml Fixture.response(:authentication) end - expect(response.response_hash["ENVELOPE"]["BODY"]).to include("AUTHENTICATE_RESPONSE") + expect(response.full_hash["ENVELOPE"]["BODY"]).to include("AUTHENTICATE_RESPONSE") end end diff --git a/spec/savon/response_spec.rb b/spec/savon/response_spec.rb index c802779d..5cb874dd 100644 --- a/spec/savon/response_spec.rb +++ b/spec/savon/response_spec.rb @@ -138,7 +138,7 @@ describe "##{method}" do it "should return the SOAP response body as a Hash" do expect(soap_response.send(method)[:authenticate_response][:return]).to eq( - Fixture.response_hash(:authentication)[:authenticate_response][:return] + Fixture.full_hash(:authentication)[:authenticate_response][:return] ) end @@ -180,7 +180,7 @@ context "when the given path exists" do it "should return an Array containing the path value" do expect(soap_response.to_array(:authenticate_response, :return)).to eq( - [Fixture.response_hash(:authentication)[:authenticate_response][:return]] + [Fixture.full_hash(:authentication)[:authenticate_response][:return]] ) end @@ -206,7 +206,7 @@ describe "#hash" do it "should return the complete SOAP response XML as a Hash" do response = soap_response :body => Fixture.response(:header) - expect(response.response_hash[:envelope][:header][:session_number]).to eq("ABCD1234") + expect(response.full_hash[:envelope][:header][:session_number]).to eq("ABCD1234") end end diff --git a/spec/support/fixture.rb b/spec/support/fixture.rb index b5dcb20d..a4777c5a 100644 --- a/spec/support/fixture.rb +++ b/spec/support/fixture.rb @@ -9,9 +9,9 @@ def [](type, fixture) fixtures(type)[fixture] ||= read_file type, fixture end - def response_hash(fixture) - @response_hash ||= {} - @response_hash[fixture] ||= nori.parse(response(fixture))[:envelope][:body] + def full_hash(fixture) + @full_hash ||= {} + @full_hash[fixture] ||= nori.parse(response(fixture))[:envelope][:body] end TYPES.each do |type, ext|