Browse Source

Add GiftCard resource

Christian Joudrey 10 years ago
parent
commit
3717b6901c

+ 7 - 0
lib/shopify_api/resources/gift_card.rb

@@ -0,0 +1,7 @@
+module ShopifyAPI
+  class GiftCard < Base
+    def disable
+      load_attributes_from_response(post(:disable))
+    end
+  end
+end

+ 20 - 0
test/fixtures/gift_card.json

@@ -0,0 +1,20 @@
+{
+  "gift_card": {
+    "api_client_id": null,
+    "balance": "10.00",
+    "created_at": "2014-08-06T15:58:38-03:00",
+    "currency": "CAD",
+    "customer_id": null,
+    "disabled_at": null,
+    "expires_on": null,
+    "id": 1023670,
+    "initial_value": "10.00",
+    "line_item_id": null,
+    "note": "",
+    "template_suffix": "",
+    "updated_at": "2014-08-06T15:58:38-03:00",
+    "user_id": 2699672,
+    "last_characters": "dddd",
+    "order_id": null
+  }
+}

+ 20 - 0
test/fixtures/gift_card_disabled.json

@@ -0,0 +1,20 @@
+{
+  "gift_card": {
+    "api_client_id": null,
+    "balance": "10.00",
+    "created_at": "2014-08-06T15:58:38-03:00",
+    "currency": "CAD",
+    "customer_id": null,
+    "disabled_at": "2014-09-13T20:15:21-03:00",
+    "expires_on": null,
+    "id": 1023670,
+    "initial_value": "10.00",
+    "line_item_id": null,
+    "note": "",
+    "template_suffix": "",
+    "updated_at": "2014-09-13T20:15:21-03:00",
+    "user_id": 2699672,
+    "last_characters": "dddd",
+    "order_id": null
+  }
+}

+ 22 - 0
test/gift_card_test.rb

@@ -0,0 +1,22 @@
+require 'test_helper'
+
+class GiftCardTest < Test::Unit::TestCase
+  def setup
+    super
+    load_gift_card
+  end
+
+  def test_disable
+    fake 'gift_cards/1023670/disable.json', :body => load_fixture('gift_card_disabled'), :method => :post, :extension => false
+
+    refute @gift_card.disabled_at
+    @gift_card.disable
+    assert @gift_card.disabled_at
+  end
+
+  private
+  def load_gift_card
+    fake 'gift_cards/1023670', :body => load_fixture('gift_card')
+    @gift_card = ShopifyAPI::GiftCard.find(1023670)
+  end
+end