Skip to content

Commit

Permalink
add countable test to expose problem with activeresource@master
Browse files Browse the repository at this point in the history
handle the case where get(:count) returns a Hash
  • Loading branch information
mikeyhew committed Jul 26, 2016
1 parent 60c1a4b commit ce387f8
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 ce387f8

Please sign in to comment.