Skip to content

Commit

Permalink
Merge pull request #356 from Shopify/fix_listing_bug
Browse files Browse the repository at this point in the history
Fix bug with listing classes
  • Loading branch information
peterjm committed Apr 27, 2017
2 parents 4a908de + 5bb93ee commit b74f47f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
@@ -1,6 +1,7 @@
== Version 4.6.0
== Version 4.7.0

* Removed the mandatory `application_id` parameter from `ShopifyAPI::ProductListing` and `ShopifyAPI::CollectionListing`
* Fixed a bug related to the non-standard primary key for `ShopifyAPI::ProductListing` and `ShopifyAPI::CollectionListing`

== Version 4.6.0

Expand Down
4 changes: 3 additions & 1 deletion lib/shopify_api/resources/collection_listing.rb
@@ -1,7 +1,9 @@
module ShopifyAPI
class CollectionListing < Base
self.primary_key = :collection_id

def product_ids
get("#{collection_id}/product_ids")
get(:product_ids)
end
end
end
2 changes: 2 additions & 0 deletions lib/shopify_api/resources/product_listing.rb
@@ -1,5 +1,7 @@
module ShopifyAPI
class ProductListing < Base
self.primary_key = :product_id

def self.product_ids
get(:product_ids)
end
Expand Down
20 changes: 18 additions & 2 deletions test/collection_listing_test.rb
Expand Up @@ -12,14 +12,30 @@ def test_get_collection_listings
assert_equal 'Home page', collection_listings.first.title
end

def test_get_collection_listing_for_collection_id
def test_get_collection_listing
fake "collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing')
fake "collection_listings//1/product_ids", method: :get, status: 201, body: load_fixture('collection_listing_product_ids')

collection_listing = ShopifyAPI::CollectionListing.find(1)

assert_equal 1, collection_listing.collection_id
assert_equal 'Home page', collection_listing.title
end

def test_get_collection_listing_reload
fake "collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing')

collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)
collection_listing.reload

assert_equal 1, collection_listing.collection_id
assert_equal 'Home page', collection_listing.title
end

def test_get_collection_listing_product_ids
fake "collection_listings/1/product_ids", method: :get, status: 201, body: load_fixture('collection_listing_product_ids')

collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)

assert_equal [1, 2], collection_listing.product_ids
end
end
11 changes: 10 additions & 1 deletion test/product_listing_test.rb
Expand Up @@ -13,13 +13,22 @@ def test_get_product_listings
assert_equal 'Rustic Copper Bottle', product_listings.last.title
end

def test_get_product_listing_for_product_id
def test_get_product_listing
fake "product_listings/2", method: :get, status: 201, body: load_fixture('product_listing')

product_listing = ShopifyAPI::ProductListing.find(2)
assert_equal 'Synergistic Silk Chair', product_listing.title
end

def test_reload_product_listing
fake "product_listings/2", method: :get, status: 201, body: load_fixture('product_listing')

product_listing = ShopifyAPI::ProductListing.new(product_id: 2)
product_listing.reload

assert_equal 'Synergistic Silk Chair', product_listing.title
end

def test_get_product_listing_product_ids
fake "product_listings/product_ids", method: :get, status: 201, body: load_fixture('product_listing_product_ids')

Expand Down

0 comments on commit b74f47f

Please sign in to comment.