Переглянути джерело

Better handling of unavailable shops for RecurringApplicationCharge

The current implementation will throw a NoMethodError: undefined method
`find' for nil:NilClass exception when calling
ShopifyAPI::RecurringApplicationCharge.current,
ShopifyAPI::RecurringApplicationCharge.pending, etc on an uninstalled or
otherwise unavailable shop.

This improvement will simply return a nil, which is consistent with
ShopifyAPI::RecurringApplicationCharge.all for the uninstalled shop
justinstern 10 роки тому
батько
коміт
c76eb2cc5a

+ 2 - 2
lib/shopify_api/resources/recurring_application_charge.rb

@@ -4,11 +4,11 @@ module ShopifyAPI
 
     class << self
       def current
-        all.find { |c| c.status == 'active' }
+        (all || []).find { |c| c.status == 'active' }
       end
 
       [:pending, :cancelled, :accepted, :declined].each do |status|
-        define_method(status) { all.select { |c| c.status == status.to_s } }
+        define_method(status) { (all || []).select { |c| c.status == status.to_s } }
       end
     end