Skip to content
This repository
Browse code

Workaround ActiveResource 3.1+ bug for saving nested resources.

  • Loading branch information...
commit 0e67bfc6c946a2b4de454028c807aff24ff2bc9b 1 parent 8081e2e
Dylan Thacker-Smith authored June 12, 2012
6  lib/shopify_api/resources/base.rb
@@ -28,7 +28,11 @@ def clear_session
28 28
         self.site = nil
29 29
         self.headers.delete('X-Shopify-Access-Token')
30 30
       end
31  
-    end                  
  31
+    end
  32
+
  33
+    def persisted?
  34
+      !id.nil?
  35
+    end
32 36
 
33 37
     private
34 38
     def only_id
4  test/fixtures/product.json
@@ -23,6 +23,7 @@
23 23
       {
24 24
         "position": 1,
25 25
         "price": "199.00",
  26
+        "product_id": 632910392,
26 27
         "created_at": "2011-10-20T14:05:13-04:00",
27 28
         "requires_shipping": true,
28 29
         "title": "Pink",
@@ -43,6 +44,7 @@
43 44
       {
44 45
         "position": 2,
45 46
         "price": "199.00",
  47
+        "product_id": 632910392,
46 48
         "created_at": "2011-10-20T14:05:13-04:00",
47 49
         "requires_shipping": true,
48 50
         "title": "Red",
@@ -63,6 +65,7 @@
63 65
       {
64 66
         "position": 3,
65 67
         "price": "199.00",
  68
+        "product_id": 632910392,
66 69
         "created_at": "2011-10-20T14:05:13-04:00",
67 70
         "requires_shipping": true,
68 71
         "title": "Green",
@@ -83,6 +86,7 @@
83 86
       {
84 87
         "position": 4,
85 88
         "price": "199.00",
  89
+        "product_id": 632910392,
86 90
         "created_at": "2011-10-20T14:05:13-04:00",
87 91
         "requires_shipping": true,
88 92
         "title": "Black",
8  test/product_test.rb
@@ -27,4 +27,12 @@ def test_get_metafields_for_product
27 27
     assert_equal 2, metafields.length
28 28
     assert metafields.all?{|m| m.is_a?(ShopifyAPI::Metafield)}
29 29
   end
  30
+
  31
+  def test_update_loaded_variant
  32
+    fake "products/632910392/variants/808950810", :method => :put, :status => 200, :body => load_fixture('variant')
  33
+
  34
+    variant = @product.variants.first
  35
+    variant.price = "0.50"
  36
+    variant.save
  37
+  end
30 38
 end

0 notes on commit 0e67bfc

Please sign in to comment.
Something went wrong with that request. Please try again.