Sfoglia il codice sorgente

Merge pull request #147 from ShopStorm/master

Better handling of unavailable shops for RecurringApplicationCharge
Christopher Saunders 10 anni fa
parent
commit
f5fff26fb2

+ 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
 

+ 8 - 0
test/recurring_application_charge_test.rb

@@ -104,4 +104,12 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
     assert_equal [], ShopifyAPI::RecurringApplicationCharge.pending
   end
 
+  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
+
 end