From 3a42b483c32091876738db155fb9359415b2fa1a Mon Sep 17 00:00:00 2001 From: marschattha <49312804+marschattha@users.noreply.github.com> Date: Thu, 14 May 2020 04:40:29 +0500 Subject: [PATCH 1/8] Update product.rb --- lib/shopify_api/resources/product.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/shopify_api/resources/product.rb b/lib/shopify_api/resources/product.rb index cf67fa6e4..ca75640ea 100644 --- a/lib/shopify_api/resources/product.rb +++ b/lib/shopify_api/resources/product.rb @@ -15,6 +15,15 @@ def price_range format % prices.min end end + + def total_inventory=(new_value) + raise_deprecated_inventory_call('total_inventory') unless allow_inventory_params? + super + end + + def serializable_hash(options = {}) + allow_inventory_params? ? super(options) : super(options).except('total_inventory') + end def collections CustomCollection.find(:all, :params => {:product_id => self.id}) @@ -31,5 +40,17 @@ def add_to_collection(collection) def remove_from_collection(collection) collection.remove_product(self) end + + private + + def raise_deprecated_inventory_call(parameter) + raise(ShopifyAPI::ValidationException, + "'#{parameter}' is deprecated - see https://help.shopify.com/en/api/guides/inventory-migration-guide", + ) + end + + def allow_inventory_params? + Base.api_version < ApiVersion.find_version('2019-10') + end end end From a19caa39455e63278a6adf671e7dbae84c6bad81 Mon Sep 17 00:00:00 2001 From: marschattha <49312804+marschattha@users.noreply.github.com> Date: Thu, 14 May 2020 04:49:40 +0500 Subject: [PATCH 2/8] Update variant.rb --- lib/shopify_api/resources/variant.rb | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/shopify_api/resources/variant.rb b/lib/shopify_api/resources/variant.rb index 76ab4da49..4c9dddf73 100644 --- a/lib/shopify_api/resources/variant.rb +++ b/lib/shopify_api/resources/variant.rb @@ -4,5 +4,42 @@ class Variant < Base include DisablePrefixCheck conditional_prefix :product + + def inventory_quantity_adjustment=(new_value) + raise_deprecated_inventory_call('inventory_quantity_adjustment') unless allow_inventory_params? + super + end + + def inventory_quantity=(new_value) + raise_deprecated_inventory_call('inventory_quantity') unless allow_inventory_params? + super + end + + def old_inventory_quantity=(new_value) + raise_deprecated_inventory_call('old_inventory_quantity') unless allow_inventory_params? + super + end + + def serializable_hash(options = {}) + if allow_inventory_params? + super(options) + else + super(options).tap do |serialized_hash| + (serialized_hash['variant'] || serialized_hash).except!('inventory_quantity', 'old_inventory_quantity') + end + end + end + + private + + def raise_deprecated_inventory_call(parameter) + raise(ShopifyAPI::ValidationException, + "'#{parameter}' is deprecated - see https://help.shopify.com/en/api/guides/inventory-migration-guide", + ) + end + + def allow_inventory_params? + Base.api_version < ApiVersion.find_version('2019-10') + end end end From 95673e5351e77a4d2eb1802d4a4b0d00298ec277 Mon Sep 17 00:00:00 2001 From: marschattha <49312804+marschattha@users.noreply.github.com> Date: Thu, 14 May 2020 04:56:01 +0500 Subject: [PATCH 3/8] Update variant.rb --- lib/shopify_api/resources/variant.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/shopify_api/resources/variant.rb b/lib/shopify_api/resources/variant.rb index 4c9dddf73..b1931ff0e 100644 --- a/lib/shopify_api/resources/variant.rb +++ b/lib/shopify_api/resources/variant.rb @@ -24,8 +24,8 @@ def serializable_hash(options = {}) if allow_inventory_params? super(options) else - super(options).tap do |serialized_hash| - (serialized_hash['variant'] || serialized_hash).except!('inventory_quantity', 'old_inventory_quantity') + super(options).tap do |resource| + (resource['variant'] || resource).except!('inventory_quantity', 'old_inventory_quantity') end end end From 43c365f29b5019a5a72911d06f0be12d8b7b72e3 Mon Sep 17 00:00:00 2001 From: marschattha <49312804+marschattha@users.noreply.github.com> Date: Thu, 14 May 2020 04:58:12 +0500 Subject: [PATCH 4/8] Update product_test.rb --- test/product_test.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/product_test.rb b/test/product_test.rb index fe5bd6621..cca18b54a 100644 --- a/test/product_test.rb +++ b/test/product_test.rb @@ -57,4 +57,43 @@ def test_price_range_when_has_different_price assert_equal('100.00 - 199.00', @product.price_range) end + + def test_deprecated_variant_inventory_fields_are_included_in_2019_07 + ShopifyAPI::Base.api_version = '2019-07' + variant = @product.variants.first + assert variant.as_json.include?('inventory_quantity') + end + + def test_deprecated_variant_inventory_fields_are_removed_in_2020_01 + ShopifyAPI::Base.api_version = '2020-01' + variant = @product.variants.first + refute variant.as_json.include?('inventory_quantity') + end + + def test_deprecated_inventory_fields_are_removed_in_2020_01 + ShopifyAPI::Base.api_version = '2020-01' + refute @product.as_json.include?('total_inventory') + end + + def test_setting_product_total_inventory_passes_in_api_before_2019_10 + ShopifyAPI::Base.api_version = '2019-07' + fake("products/632910392", {:body => load_fixture('product')}) + @product.total_inventory = 8 + end + + def test_setting_product_total_inventory_fails_in_2019_10_api + ShopifyAPI::Base.api_version = '2019-10' + fake("products/632910392", {:body => load_fixture('product')}) + assert_raises(ShopifyAPI::ValidationException) do + @product.total_inventory = 8 + end + end + + def test_setting_product_total_inventory_fails_in_the_unstable_api + ShopifyAPI::Base.api_version = :unstable + fake("products/632910392", {:body => load_fixture('product')}) + assert_raises(ShopifyAPI::ValidationException) do + @product.total_inventory = 8 + end + end end From 7b6615cc67ad7688b34d261f48af0ff430e52b5c Mon Sep 17 00:00:00 2001 From: marschattha <49312804+marschattha@users.noreply.github.com> Date: Thu, 14 May 2020 04:59:16 +0500 Subject: [PATCH 5/8] Update variant_test.rb --- test/variant_test.rb | 89 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/test/variant_test.rb b/test/variant_test.rb index 9bac02386..8b0bed14f 100644 --- a/test/variant_test.rb +++ b/test/variant_test.rb @@ -43,4 +43,93 @@ def test_delete_variant v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert v.destroy end + + def test_deprecated_inventory_fields_are_included_in_2019_07 + ShopifyAPI::Base.api_version = '2019-07' + fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) + assert variant.as_json.include?('inventory_quantity') + end + + def test_deprecated_inventory_fields_are_removed_in_2020_01 + ShopifyAPI::Base.api_version = '2020-01' + fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) + refute variant.as_json.include?('inventory_quantity') + end + + def test_setting_variant_inventory_quantity_adjustment_passes_in_api_before_2019_10 + ShopifyAPI::Base.api_version = '2019-07' + fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) + variant.inventory_quantity_adjustment = 8 + end + + def test_setting_variant_inventory_quantity_adjustment_fails_in_2019_10_api + ShopifyAPI::Base.api_version = '2019-10' + fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) + assert_raises(ShopifyAPI::ValidationException) do + variant.inventory_quantity_adjustment = 8 + end + end + + def test_setting_variant_inventory_quantity_adjustment_fails_in_the_unstable_api + ShopifyAPI::Base.api_version = :unstable + fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) + assert_raises(ShopifyAPI::ValidationException) do + variant.inventory_quantity_adjustment = 8 + end + end + + def test_setting_variant_inventory_quantity_passes_in_api_before_2019_10 + ShopifyAPI::Base.api_version = '2019-07' + fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) + variant.inventory_quantity = 8 + end + + def test_setting_variant_inventory_quantity_fails_in_2019_10_api + ShopifyAPI::Base.api_version = '2019-10' + fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) + assert_raises(ShopifyAPI::ValidationException) do + variant.inventory_quantity = 8 + end + end + + def test_setting_variant_inventory_quantity_fails_in_the_unstable_api + ShopifyAPI::Base.api_version = :unstable + fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) + assert_raises(ShopifyAPI::ValidationException) do + variant.inventory_quantity = 8 + end + end + + def test_setting_variant_old_inventory_quantity_passes_in_api_before_2019_10 + ShopifyAPI::Base.api_version = '2019-07' + fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) + variant.old_inventory_quantity = 8 + end + + def test_setting_variant_old_inventory_quantity_fails_in_2019_10_api + ShopifyAPI::Base.api_version = '2019-10' + fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) + assert_raises(ShopifyAPI::ValidationException) do + variant.old_inventory_quantity = 8 + end + end + + def test_setting_variant_old_inventory_quantity_fails_in_the_unstable_api + ShopifyAPI::Base.api_version = :unstable + fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) + assert_raises(ShopifyAPI::ValidationException) do + variant.old_inventory_quantity = 8 + end + end end From 7f6657aebb7b1d81e22812c6e1d0657e00e5b6e5 Mon Sep 17 00:00:00 2001 From: marschattha <49312804+marschattha@users.noreply.github.com> Date: Fri, 15 May 2020 02:57:34 +0500 Subject: [PATCH 6/8] Added api versions to make tests work --- test/variant_test.rb | 88 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 12 deletions(-) diff --git a/test/variant_test.rb b/test/variant_test.rb index 8b0bed14f..9f6c86d26 100644 --- a/test/variant_test.rb +++ b/test/variant_test.rb @@ -1,6 +1,15 @@ require 'test_helper' class VariantTest < Test::Unit::TestCase + def setup + super + + @version_unstable = ShopifyAPI::ApiVersion.find_version('unstable') + @version_2019_07 = ShopifyAPI::ApiVersion.find_version('2019-07') + @version_2019_10 = ShopifyAPI::ApiVersion.find_version('2019-10') + @version_2020_01 = ShopifyAPI::ApiVersion.find_version('2020-01') + + end def test_get_variants fake "products/632910392/variants", :method => :get, :body => load_fixture('variants') @@ -43,31 +52,51 @@ def test_delete_variant v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert v.destroy end - + def test_deprecated_inventory_fields_are_included_in_2019_07 ShopifyAPI::Base.api_version = '2019-07' - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + fake( + "products/632910392/variants/808950810", + method: :get, + body: load_fixture('variant'), + api_version: @version_2019_07 + ) variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert variant.as_json.include?('inventory_quantity') end def test_deprecated_inventory_fields_are_removed_in_2020_01 ShopifyAPI::Base.api_version = '2020-01' - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + fake( + "products/632910392/variants/808950810", + method: :get, + body: load_fixture('variant'), + api_version: @version_2020_01 + ) variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) refute variant.as_json.include?('inventory_quantity') end def test_setting_variant_inventory_quantity_adjustment_passes_in_api_before_2019_10 ShopifyAPI::Base.api_version = '2019-07' - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + fake( + "products/632910392/variants/808950810", + method: :get, + body: load_fixture('variant'), + api_version: @version_2019_07 + ) variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) variant.inventory_quantity_adjustment = 8 end def test_setting_variant_inventory_quantity_adjustment_fails_in_2019_10_api ShopifyAPI::Base.api_version = '2019-10' - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + fake( + "products/632910392/variants/808950810", + method: :get, + body: load_fixture('variant'), + api_version: @version_2019_10 + ) variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert_raises(ShopifyAPI::ValidationException) do variant.inventory_quantity_adjustment = 8 @@ -76,7 +105,12 @@ def test_setting_variant_inventory_quantity_adjustment_fails_in_2019_10_api def test_setting_variant_inventory_quantity_adjustment_fails_in_the_unstable_api ShopifyAPI::Base.api_version = :unstable - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + fake( + "products/632910392/variants/808950810", + method: :get, + body: load_fixture('variant'), + api_version: @version_unstable + ) variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert_raises(ShopifyAPI::ValidationException) do variant.inventory_quantity_adjustment = 8 @@ -85,14 +119,24 @@ def test_setting_variant_inventory_quantity_adjustment_fails_in_the_unstable_api def test_setting_variant_inventory_quantity_passes_in_api_before_2019_10 ShopifyAPI::Base.api_version = '2019-07' - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + fake( + "products/632910392/variants/808950810", + method: :get, + body: load_fixture('variant'), + api_version: @version_2019_07 + ) variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) variant.inventory_quantity = 8 end def test_setting_variant_inventory_quantity_fails_in_2019_10_api ShopifyAPI::Base.api_version = '2019-10' - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + fake( + "products/632910392/variants/808950810", + method: :get, + body: load_fixture('variant'), + api_version: @version_2019_10 + ) variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert_raises(ShopifyAPI::ValidationException) do variant.inventory_quantity = 8 @@ -101,7 +145,12 @@ def test_setting_variant_inventory_quantity_fails_in_2019_10_api def test_setting_variant_inventory_quantity_fails_in_the_unstable_api ShopifyAPI::Base.api_version = :unstable - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + fake( + "products/632910392/variants/808950810", + method: :get, + body: load_fixture('variant'), + api_version: @version_unstable + ) variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert_raises(ShopifyAPI::ValidationException) do variant.inventory_quantity = 8 @@ -110,14 +159,24 @@ def test_setting_variant_inventory_quantity_fails_in_the_unstable_api def test_setting_variant_old_inventory_quantity_passes_in_api_before_2019_10 ShopifyAPI::Base.api_version = '2019-07' - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + fake( + "products/632910392/variants/808950810", + method: :get, + body: load_fixture('variant'), + api_version: @version_2019_07 + ) variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) variant.old_inventory_quantity = 8 end def test_setting_variant_old_inventory_quantity_fails_in_2019_10_api ShopifyAPI::Base.api_version = '2019-10' - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + fake( + "products/632910392/variants/808950810", + method: :get, + body: load_fixture('variant'), + api_version: @version_2019_10 + ) variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert_raises(ShopifyAPI::ValidationException) do variant.old_inventory_quantity = 8 @@ -126,7 +185,12 @@ def test_setting_variant_old_inventory_quantity_fails_in_2019_10_api def test_setting_variant_old_inventory_quantity_fails_in_the_unstable_api ShopifyAPI::Base.api_version = :unstable - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') + fake( + "products/632910392/variants/808950810", + method: :get, + body: load_fixture('variant'), + api_version: @version_unstable + ) variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert_raises(ShopifyAPI::ValidationException) do variant.old_inventory_quantity = 8 From a08eb6c9c08c653f73c3ca9543bda9d9baa15363 Mon Sep 17 00:00:00 2001 From: marschattha <49312804+marschattha@users.noreply.github.com> Date: Fri, 15 May 2020 03:49:01 +0500 Subject: [PATCH 7/8] variant_test.rb cleanup --- test/variant_test.rb | 130 ++++++------------------------------------- 1 file changed, 18 insertions(+), 112 deletions(-) diff --git a/test/variant_test.rb b/test/variant_test.rb index 9f6c86d26..278190639 100644 --- a/test/variant_test.rb +++ b/test/variant_test.rb @@ -3,12 +3,8 @@ class VariantTest < Test::Unit::TestCase def setup super - - @version_unstable = ShopifyAPI::ApiVersion.find_version('unstable') - @version_2019_07 = ShopifyAPI::ApiVersion.find_version('2019-07') - @version_2019_10 = ShopifyAPI::ApiVersion.find_version('2019-10') - @version_2020_01 = ShopifyAPI::ApiVersion.find_version('2020-01') - + fake "products/632910392/variants/808950810", method: :get, body: load_fixture('variant') + @variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) end def test_get_variants @@ -19,181 +15,91 @@ def test_get_variants end def test_get_variant_namespaced - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') - - v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) - assert_equal 632910392, v.product_id + assert_equal 632910392, @variant.product_id end def test_get_variant - fake "variants/808950810", :method => :get, :body => load_fixture('variant') - - v = ShopifyAPI::Variant.find(808950810) - assert_equal 632910392, v.product_id + assert_equal 632910392, @variant.product_id end def test_product_id_should_be_accessible_if_via_product_endpoint - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') - - v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) - assert_equal 632910392, v.product_id + assert_equal 632910392, @variant.product_id end def test_product_id_should_be_accessible_if_via_variant_endpoint fake "variants/808950810", :method => :get, :body => load_fixture('variant') - - v = ShopifyAPI::Variant.find(808950810) - assert_equal 632910392, v.product_id + assert_equal 632910392, @variant.product_id end def test_delete_variant - fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant') fake "products/632910392/variants/808950810", :method => :delete, :body => 'destroyed' - v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) - assert v.destroy + assert @variant.destroy end def test_deprecated_inventory_fields_are_included_in_2019_07 ShopifyAPI::Base.api_version = '2019-07' - fake( - "products/632910392/variants/808950810", - method: :get, - body: load_fixture('variant'), - api_version: @version_2019_07 - ) - variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) - assert variant.as_json.include?('inventory_quantity') + assert @variant.as_json.include?('inventory_quantity') end def test_deprecated_inventory_fields_are_removed_in_2020_01 ShopifyAPI::Base.api_version = '2020-01' - fake( - "products/632910392/variants/808950810", - method: :get, - body: load_fixture('variant'), - api_version: @version_2020_01 - ) - variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) - refute variant.as_json.include?('inventory_quantity') + refute @variant.as_json.include?('inventory_quantity') end def test_setting_variant_inventory_quantity_adjustment_passes_in_api_before_2019_10 ShopifyAPI::Base.api_version = '2019-07' - fake( - "products/632910392/variants/808950810", - method: :get, - body: load_fixture('variant'), - api_version: @version_2019_07 - ) - variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) - variant.inventory_quantity_adjustment = 8 + @variant.inventory_quantity_adjustment = 8 end def test_setting_variant_inventory_quantity_adjustment_fails_in_2019_10_api ShopifyAPI::Base.api_version = '2019-10' - fake( - "products/632910392/variants/808950810", - method: :get, - body: load_fixture('variant'), - api_version: @version_2019_10 - ) - variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert_raises(ShopifyAPI::ValidationException) do - variant.inventory_quantity_adjustment = 8 + @variant.inventory_quantity_adjustment = 8 end end def test_setting_variant_inventory_quantity_adjustment_fails_in_the_unstable_api ShopifyAPI::Base.api_version = :unstable - fake( - "products/632910392/variants/808950810", - method: :get, - body: load_fixture('variant'), - api_version: @version_unstable - ) - variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert_raises(ShopifyAPI::ValidationException) do - variant.inventory_quantity_adjustment = 8 + @variant.inventory_quantity_adjustment = 8 end end def test_setting_variant_inventory_quantity_passes_in_api_before_2019_10 ShopifyAPI::Base.api_version = '2019-07' - fake( - "products/632910392/variants/808950810", - method: :get, - body: load_fixture('variant'), - api_version: @version_2019_07 - ) - variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) - variant.inventory_quantity = 8 + @variant.inventory_quantity = 8 end def test_setting_variant_inventory_quantity_fails_in_2019_10_api ShopifyAPI::Base.api_version = '2019-10' - fake( - "products/632910392/variants/808950810", - method: :get, - body: load_fixture('variant'), - api_version: @version_2019_10 - ) - variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert_raises(ShopifyAPI::ValidationException) do - variant.inventory_quantity = 8 + @variant.inventory_quantity = 8 end end def test_setting_variant_inventory_quantity_fails_in_the_unstable_api ShopifyAPI::Base.api_version = :unstable - fake( - "products/632910392/variants/808950810", - method: :get, - body: load_fixture('variant'), - api_version: @version_unstable - ) - variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert_raises(ShopifyAPI::ValidationException) do - variant.inventory_quantity = 8 + @variant.inventory_quantity = 8 end end def test_setting_variant_old_inventory_quantity_passes_in_api_before_2019_10 ShopifyAPI::Base.api_version = '2019-07' - fake( - "products/632910392/variants/808950810", - method: :get, - body: load_fixture('variant'), - api_version: @version_2019_07 - ) - variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) - variant.old_inventory_quantity = 8 + @variant.old_inventory_quantity = 8 end def test_setting_variant_old_inventory_quantity_fails_in_2019_10_api ShopifyAPI::Base.api_version = '2019-10' - fake( - "products/632910392/variants/808950810", - method: :get, - body: load_fixture('variant'), - api_version: @version_2019_10 - ) - variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert_raises(ShopifyAPI::ValidationException) do - variant.old_inventory_quantity = 8 + @variant.old_inventory_quantity = 8 end end def test_setting_variant_old_inventory_quantity_fails_in_the_unstable_api ShopifyAPI::Base.api_version = :unstable - fake( - "products/632910392/variants/808950810", - method: :get, - body: load_fixture('variant'), - api_version: @version_unstable - ) - variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392}) assert_raises(ShopifyAPI::ValidationException) do - variant.old_inventory_quantity = 8 + @variant.old_inventory_quantity = 8 end end end From cd6d797abb62f84b80bccc23698502b27c51024f Mon Sep 17 00:00:00 2001 From: marschattha <49312804+marschattha@users.noreply.github.com> Date: Fri, 15 May 2020 03:52:53 +0500 Subject: [PATCH 8/8] one line missed from previous cleanup --- test/variant_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/variant_test.rb b/test/variant_test.rb index 278190639..5a0dcc580 100644 --- a/test/variant_test.rb +++ b/test/variant_test.rb @@ -27,7 +27,6 @@ def test_product_id_should_be_accessible_if_via_product_endpoint end def test_product_id_should_be_accessible_if_via_variant_endpoint - fake "variants/808950810", :method => :get, :body => load_fixture('variant') assert_equal 632910392, @variant.product_id end