Skip to content

Commit

Permalink
shortcut for accessing the response hash
Browse files Browse the repository at this point in the history
response.to_hash[:authenticate_response]  # old
response[:authenticate_response]          # new
  • Loading branch information
rubiii committed Apr 5, 2011
1 parent c6a21ee commit 1ffcd23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/savon/soap/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def header
@header_hash ||= basic_hash.find_soap_header
end

# Shortcut for the +to_hash+ method.
def [](key)
to_hash[key]
end

# Returns the SOAP response body as a Hash.
def to_hash
@hash ||= Savon::SOAP::XML.to_hash basic_hash
Expand Down
7 changes: 7 additions & 0 deletions spec/savon/soap/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@
end
end

describe "#[]" do
it "should return the SOAP response body as a Hash" do
soap_response[:authenticate_response][:return].should ==
Fixture.response_hash(:authentication)[:authenticate_response][:return]
end
end

describe "#to_hash" do
it "should return the SOAP response body as a Hash" do
soap_response.to_hash[:authenticate_response][:return].should ==
Expand Down

0 comments on commit 1ffcd23

Please sign in to comment.