Skip to content

Commit

Permalink
fixed SOAPFault hash key access. closes #393
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiii committed Apr 21, 2013
1 parent ed6e9c1 commit a1fd031
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
* Fix: [#430](https://github.com/savonrb/savon/pull/430) allows you to rescue and ignore
`Savon::Error` errors in production while still having mocks trigger test failures.

* Fix: [#393](https://github.com/savonrb/savon/pull/393) changed `Savon::SOAPFault` to work
with generic response Hash keys.

### 2.1.0 (2013-02-03)

* Feature: [#372](https://github.com/savonrb/savon/pull/372) added global `ssl_cert_key_password` option.
Expand Down
20 changes: 14 additions & 6 deletions lib/savon/soap_fault.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,28 @@ def initialize(http, nori)
attr_reader :http, :nori

def to_s
message_by_version to_hash[:fault]
fault = nori.find(to_hash, 'Fault')
message_by_version(fault)
end

def to_hash
nori.parse(@http.body)[:envelope][:body]
parsed = nori.parse(@http.body)
nori.find(parsed, 'Envelope', 'Body')
end

private

def message_by_version(fault)
if fault[:faultcode]
"(#{fault[:faultcode]}) #{fault[:faultstring]}"
elsif fault[:code]
"(#{fault[:code][:value]}) #{fault[:reason][:text]}"
if nori.find(fault, 'faultcode')
code = nori.find(fault, 'faultcode')
text = nori.find(fault, 'faultstring')

"(#{code}) #{text}"
elsif nori.find(fault, 'Code')
code = nori.find(fault, 'Code', 'Value')
text = nori.find(fault, 'Reason', 'Text')

"(#{code}) #{text}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion savon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |s|

s.rubyforge_project = s.name

s.add_dependency "nori", "~> 2.0.3"
s.add_dependency "nori", "~> 2.1.0"
s.add_dependency "httpi", "~> 2.0.2"
s.add_dependency "wasabi", "~> 3.0.0"
s.add_dependency "akami", "~> 1.2.0"
Expand Down
23 changes: 20 additions & 3 deletions spec/savon/soap_fault_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
end

it "works even if the keys are different in a SOAP 1.1 fault message" do
soap_fault_nc.send method
expect(soap_fault_nc.send method).to eq("(soap:Server) Fault occurred while processing.")
end

it "works even if the keys are different in a SOAP 1.2 fault message" do
soap_fault_nc2.send method
expect(soap_fault_nc2.send method).to eq("(soap:Sender) Sender Timeout")
end
end
end
Expand Down Expand Up @@ -95,7 +95,24 @@
end

it "works even if the keys are different" do
soap_fault_nc2.to_hash
expected = {
"Fault" => {
"Code" => {
"Value" => "soap:Sender",
"Subcode"=> {
"Value" => "m:MessageTimeout"
}
},
"Reason" => {
"Text" => "Sender Timeout"
},
"Detail" => {
"MaxTime" => "P5M"
}
}
}

expect(soap_fault_nc2.to_hash).to eq(expected)
end
end

Expand Down

0 comments on commit a1fd031

Please sign in to comment.