Better handling of unavailable shops for RecurringApplicationCharge
@@ -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 } }
@@ -104,4 +104,12 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
assert_equal [], ShopifyAPI::RecurringApplicationCharge.pending
+ def test_recurring_application_charge_not_found_error
+ fake "recurring_application_charges", :body => '{"errors":"Not Found"}', :status => 404
+
+ assert_equal nil, ShopifyAPI::RecurringApplicationCharge.all
+ assert_equal nil, ShopifyAPI::RecurringApplicationCharge.current
+ assert_equal [], ShopifyAPI::RecurringApplicationCharge.pending
+ end