Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #290 from mikeyhew/fix-countable
Fix for `TypeError: can't convert Hash into Integer` when calling `Product.count` with latest activeresource
- Loading branch information
Showing
2 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |