Browse Source

add countable test to expose problem with activeresource@master

handle the case where get(:count) returns a Hash
Michael Hewson 8 years ago
parent
commit
ce387f8219
2 changed files with 20 additions and 1 deletions
  1. 8 1
      lib/shopify_api/countable.rb
  2. 12 0
      test/countable_test.rb

+ 8 - 1
lib/shopify_api/countable.rb

@@ -1,7 +1,14 @@
 module ShopifyAPI
   module Countable
     def count(options = {})
-      Integer(get(:count, options))
+      data = get(:count, options)
+
+      count = case data
+        when Hash then data["count"]
+        else data
+      end
+
+      Integer(count)
     end
   end
 end

+ 12 - 0
test/countable_test.rb

@@ -0,0 +1,12 @@
+require 'test_helper'
+
+class CountableTest < Test::Unit::TestCase
+  def setup
+    fake "products/count", :body => '{"count": 16}'
+  end
+
+  def test_count_products
+    count = ShopifyAPI::Product.count
+    assert_equal 16, count
+  end
+end