Ver código fonte

Workaround ActiveResource 3.1+ bug for saving nested resources.

Dylan Smith 12 anos atrás
pai
commit
0e67bfc6c9

+ 5 - 1
lib/shopify_api/resources/base.rb

@@ -28,7 +28,11 @@ module ShopifyAPI
         self.site = nil
         self.headers.delete('X-Shopify-Access-Token')
       end
-    end                  
+    end
+
+    def persisted?
+      !id.nil?
+    end
 
     private
     def only_id

+ 4 - 0
test/fixtures/product.json

@@ -23,6 +23,7 @@
       {
         "position": 1,
         "price": "199.00",
+        "product_id": 632910392,
         "created_at": "2011-10-20T14:05:13-04:00",
         "requires_shipping": true,
         "title": "Pink",
@@ -43,6 +44,7 @@
       {
         "position": 2,
         "price": "199.00",
+        "product_id": 632910392,
         "created_at": "2011-10-20T14:05:13-04:00",
         "requires_shipping": true,
         "title": "Red",
@@ -63,6 +65,7 @@
       {
         "position": 3,
         "price": "199.00",
+        "product_id": 632910392,
         "created_at": "2011-10-20T14:05:13-04:00",
         "requires_shipping": true,
         "title": "Green",
@@ -83,6 +86,7 @@
       {
         "position": 4,
         "price": "199.00",
+        "product_id": 632910392,
         "created_at": "2011-10-20T14:05:13-04:00",
         "requires_shipping": true,
         "title": "Black",

+ 8 - 0
test/product_test.rb

@@ -27,4 +27,12 @@ class ProductTest < Test::Unit::TestCase
     assert_equal 2, metafields.length
     assert metafields.all?{|m| m.is_a?(ShopifyAPI::Metafield)}
   end
+
+  def test_update_loaded_variant
+    fake "products/632910392/variants/808950810", :method => :put, :status => 200, :body => load_fixture('variant')
+
+    variant = @product.variants.first
+    variant.price = "0.50"
+    variant.save
+  end
 end