chargify / chargify_api_ares

A Chargify API wrapper for Ruby using ActiveResource
http://chargify.com
MIT License
161 stars 96 forks source link

2013 override causes an ArgumentError in the Migration class #117

Closed weppos closed 8 years ago

weppos commented 8 years ago

We recently started to experience this error

Failure/Error: subject.migrate("Gold")
ArgumentError:
  wrong number of arguments (2 for 1)
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/validations.rb:19:in `[]'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/validations.rb:19:in `block (2 levels) in from_array'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/validations.rb:18:in `each'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/validations.rb:18:in `detect'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/validations.rb:18:in `block in from_array'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/validations.rb:17:in `each'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/validations.rb:17:in `from_array'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/chargify_api_ares-1.3.5/lib/chargify_api_ares/resources/migration.rb:22:in `load_remote_errors'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/validations.rb:126:in `rescue in save_with_validation'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/validations.rb:109:in `save_with_validation'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/observing.rb:21:in `save_with_notifications'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/base.rb:806:in `block in create'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/base.rb:806:in `tap'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/activeresource-4.0.0/lib/active_resource/base.rb:806:in `create'
# /Users/weppos/.rvm/gems/ruby-2.1.5@dnsimple/gems/chargify_api_ares-1.3.5/lib/chargify_api_ares/resources/subscription.rb:101:in `migrate'

It looks like the cause of this issue is an override of the load_remote_errors method created in 2013.

Removing this override and falling back to the original implementation seems to work as expected.

This is an example response (without the unnecessary headers)

HTTP/1.1 422 Unprocessable Entity
Cache-Control: must-revalidate, private, max-age=0
Content-Type: application/xml; charset=utf-8
Date: Sun, 27 Sep 2015 19:00:53 GMT

<?xml version="1.0" encoding="UTF-8"?><errors><error>Your card was declined.</error></errors>

Any chance that the response was recently changed at Chargify?

speric commented 8 years ago

@weppos we did in fact recently change the errors response from:

 <errors>Your card was declined.</errors>

To something more idiomatic:

<errors>
    <error>Your card was declined.</error>
</errors>

Obviously we neglected to ensure this change wouldn't break the gem. We'll work on fixing this ASAP. Sorry for the confusion!

weppos commented 8 years ago

Cool! Let me know if you want me to provide a patch.

speric commented 8 years ago

@weppos sure, PRs are always welcome. :smile: