Browse files

Handle ErrorResults that do not have a status.

  • Loading branch information...
1 parent f286ddf commit be023b46659ec8eeb9b1163a5fde658c03932203 @halogenandtoast halogenandtoast committed Jun 8, 2012
Showing with 13 additions and 5 deletions.
  1. +7 −5 lib/ashmont/errors.rb
  2. +6 −0 spec/ashmont/errors_spec.rb
View
12 lib/ashmont/errors.rb
@@ -20,11 +20,13 @@ def to_hash
private
def parse_result(result)
- case result.status
- when "processor_declined"
- add_error :number, "was denied by the payment processor with the message: #{result.processor_response_text}"
- when "gateway_rejected"
- add_error :cvv, "did not match"
+ if result.respond_to?(:status)
+ case result.status
+ when "processor_declined"
+ add_error :number, "was denied by the payment processor with the message: #{result.processor_response_text}"
+ when "gateway_rejected"
+ add_error :cvv, "did not match"
+ end
end
end
View
6 spec/ashmont/errors_spec.rb
@@ -30,6 +30,12 @@
should include("expiration_year is unsupported")
end
+ it "handles error results without a status" do
+ result = {}
+ errors = [ stub("error", :attribute => "foo", :message => "bar") ]
+ expect { Ashmont::Errors.new(result, errors).to_hash }.to_not raise_error(NoMethodError)
+ end
+
def errors_for(options = {})
result = stub("result",
:status => options[:status] || "rejected",

0 comments on commit be023b4

Please sign in to comment.