Skip to content

Commit

Permalink
Merge pull request #290 from mikeyhew/fix-countable
Browse files Browse the repository at this point in the history
Fix for `TypeError: can't convert Hash into Integer` when calling `Product.count` with latest activeresource
  • Loading branch information
kevinhughes27 committed Jul 26, 2016
2 parents 60c1a4b + ce387f8 commit d2b4014
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion 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 changes: 12 additions & 0 deletions 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

0 comments on commit d2b4014

Please sign in to comment.