chargify / chargify_api_ares

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

undefined method 'cancel' for Subscription #38

Closed jwoertink closed 10 years ago

jwoertink commented 12 years ago

If you find a subscription through a customer, then methods like cancel, and reactivate won't exist. This is shown through

Chargify::Customer::Subscritpion.instance_methods(false).include?(:cancel) #=> false
Chargify::Subscription.instance_methods(false).include?(:cancel) #=> true

It looks like there are two different Subscription classes due to the scope.

customer = Chargify::Customer.find_by_reference(some_reference_id)
subscription = chargify_customer.subscriptions.first
puts subscription.class #=> Chargify::Customer::Subscription
real_subscription = Chargify::Subscription.find(subscription.id)
puts real_subscription.class #=> Chargify::Subscription

So calling cancel on subscription would throw an error, but calling cancel on real_subscription would work fine.

jeremywrowe commented 10 years ago

This is expected behavior and all actions should be called on the real_ object :) The problem with this gem is that we are using active resource that feels much like active record. This causes a lot of confusion.

This is more of a shout out just so others will know what to do if they stumble on this as well.

Thanks for the report!