Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing getters on Savon::Response soap_fault/soap_error #450

Merged
merged 1 commit into from
May 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## master

* Fix: [#450](https://github.com/savonrb/savon/pull/450) Add back attr_readers Response#soap_fault and Response#http_error

* Feature: [#402](https://github.com/savonrb/savon/issues/402) Makes it possible to create mocks that don't care about the message sent: `savon.expects(:authenticate).with(message: :any)`.

* Feature: [#424](https://github.com/savonrb/savon/issues/424) Adds support for multipart responses
Expand Down
12 changes: 9 additions & 3 deletions lib/savon/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ def initialize(http, globals, locals)
@globals = globals
@locals = locals

build_soap_and_http_errors!
raise_soap_and_http_errors! if @globals[:raise_errors]
end

attr_reader :http, :globals, :locals
attr_reader :http, :globals, :locals, :soap_fault, :http_error

def success?
!soap_fault? && !http_error?
Expand Down Expand Up @@ -66,9 +67,14 @@ def xpath(path, namespaces = nil)

private

def build_soap_and_http_errors!
@soap_fault = SOAPFault.new(@http, nori) if soap_fault?
@http_error = HTTPError.new(@http) if http_error?
end

def raise_soap_and_http_errors!
raise SOAPFault.new(@http, nori) if soap_fault?
raise HTTPError.new(@http) if http_error?
raise soap_fault if soap_fault?
raise http_error if http_error?
end

def raise_invalid_response_error!
Expand Down
24 changes: 24 additions & 0 deletions spec/savon/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
end
end

describe "#soap_fault" do
before { globals[:raise_errors] = false }

it "should return nil in case the response seems to be ok" do
soap_response.soap_fault.should be_nil
end

it "should return a SOAPFault in case of a SOAP fault" do
soap_fault_response.soap_fault.should be_a(Savon::SOAPFault)
end
end

describe "#http_error?" do
before { globals[:raise_errors] = false }

Expand All @@ -65,6 +77,18 @@
end
end

describe "#http_error" do
before { globals[:raise_errors] = false }

it "should return nil in case the response seems to be ok" do
soap_response.http_error.should be_nil
end

it "should return a HTTPError in case of an HTTP error" do
soap_response(:code => 500).http_error.should be_a(Savon::HTTPError)
end
end

describe "#header" do
it "should return the SOAP response header as a Hash" do
response = soap_response :body => Fixture.response(:header)
Expand Down