Skip to content

Commit

Permalink
Fix parsing transparent errors with no attributes. Apply new error at…
Browse files Browse the repository at this point in the history
…tribute parsing to non-transparent post errors. Bump version to 0.4.4.
  • Loading branch information
isaachall committed Apr 5, 2011
1 parent 0c0ae17 commit 79784bc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
11 changes: 8 additions & 3 deletions lib/recurly/base.rb
Expand Up @@ -27,7 +27,12 @@ def save
rescue ActiveResource::ResourceInvalid => error
case error.response['Content-Type']
when /application\/xml/
errors.from_xml(error.response.body)
begin
f = Recurly::Formats::XmlWithErrorsFormat.new
load_errors_from_array(f.decode(error.response.body))
rescue
errors.from_xml(error.response.body)
end
when /application\/json/
errors.from_json(error.response.body)
end
Expand Down Expand Up @@ -103,8 +108,8 @@ def load_errors_from_array(new_errors, save_cache = false)
errors[:base] << message
end

humanized_name = field.humanize
message = message[(humanized_name.size + 1)..-1] if message[0, humanized_name.size + 1] == "#{humanized_name} "
humanized_name = field.humanize.downcase
message = message[(humanized_name.size + 1)..-1] if message[0, humanized_name.size + 1].downcase == "#{humanized_name} "

errors.add field.to_sym, message
elsif error.is_a?(String)
Expand Down
4 changes: 2 additions & 2 deletions lib/recurly/formats/xml_with_errors.rb
Expand Up @@ -32,7 +32,7 @@ def xml_node_to_hash(node)
elsif node_type == 'array'
return node.children.collect do |child|
xml_node_to_hash(child)
end
end.reject { |n| n.nil? || (n.is_a?(String) && n.blank?) }
end

return nil if node.children.empty?
Expand Down Expand Up @@ -92,7 +92,7 @@ def xml_node_type(node)
end

def xml_attributes(node)
return nil if node.attribute_nodes.empty?
return {} if node.attribute_nodes.empty?
values = {}
node.attribute_nodes.each do |attribute|
values[attribute.name] = attribute.value
Expand Down
2 changes: 1 addition & 1 deletion lib/recurly/version.rb
@@ -1,3 +1,3 @@
module Recurly #:nodoc
VERSION = "0.4.3"
VERSION = "0.4.4"
end
6 changes: 3 additions & 3 deletions spec/integration/account_spec.rb
Expand Up @@ -219,8 +219,8 @@ module Recurly
end

it "should require setting an account code" do
@account.errors[:base].should include("account code can't be blank")
@account.errors[:base].should include("account code is invalid")
@account.errors[:account_code].should include("can't be blank")
@account.errors[:account_code].should include("is invalid")
end
end

Expand All @@ -237,7 +237,7 @@ module Recurly
end

it "should require setting an account code" do
@account.errors[:base].should include("account code has already been taken")
@account.errors[:account_code].should include("has already been taken")
end
end
end
Expand Down

0 comments on commit 79784bc

Please sign in to comment.