Sha256: 16fa92feebc35e9058a11c5f57284d0c4307c6fb9381dabb21e9976c26f2adee

Contents?: true

Size: 1.99 KB

Versions: 49

Compression:

Stored size: 1.99 KB

Contents

require 'test_helper'

class MetafieldTest < Test::Unit::TestCase
  def test_get_metafields
    fake "metafields", :method => :get, :body => load_fixture('metafields')
    metafields = ShopifyAPI::Metafield.find(:all)
  end

  def test_get_metafield
    fake "metafields/721389482", :method => :get, :body => load_fixture('metafield')
    assert ShopifyAPI::Metafield.find(721389482)
  end

  def test_get_metafield_of_a_blog
    fake "blogs/1008414260/metafields/721389482", :method => :get, :body => load_fixture('metafield')
    metafield = ShopifyAPI::Metafield.find(721389482, :params => {:resource => "blogs", :resource_id => 1008414260})
    assert_equal 1008414260, metafield.prefix_options[:resource_id]
  end

  def test_create_metafield_for_a_blog
    fake "blogs/1008414260", :method => :get, :body => load_fixture('blog')
    fake "blogs/1008414260/metafields", :method => :post, :status => 201, :body => load_fixture('metafield')

    blog = ShopifyAPI::Blog.find(1008414260)
    metafield = blog.add_metafield(ShopifyAPI::Metafield.new(:namespace => "summaries", :key => "First Summary", :value => "Make commerce better", :value_type => "string"))

    assert_equal ActiveSupport::JSON.decode('{"metafield":{"namespace":"summaries","key":"First Summary","value":"Make commerce better","value_type":"string"}}'), ActiveSupport::JSON.decode(FakeWeb.last_request.body)
    assert !metafield.new_record?
  end

  def test_update_metafield
    fake "metafields/721389482", :method => :get, :body => load_fixture('metafield')
    fake "metafields/721389482", :method => :put, :status => 200, :body => load_fixture('metafield')
    metafield = ShopifyAPI::Metafield.find(721389482)
    metafield.namespace = "teaser"
    assert metafield.save
  end

  def test_delete_metafield
    fake "metafields/721389482", :method => :get, :body => load_fixture('metafield')
    fake "metafields/721389482", :method => :delete, :body => 'destroyed'
    metafield = ShopifyAPI::Metafield.find(721389482)
    assert metafield.destroy
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
shopify_api-7.0.2 test/metafield_test.rb
shopify_api-7.0.1 test/metafield_test.rb
shopify_api-7.0.0 test/metafield_test.rb
shopify_api-6.0.0 test/metafield_test.rb
shopify_api-5.2.4 test/metafield_test.rb
shopify_api-5.2.3 test/metafield_test.rb
shopify_api-5.2.2 test/metafield_test.rb
shopify_api-5.2.1 test/metafield_test.rb
shopify_api-5.2.0 test/metafield_test.rb
shopify_api-5.1.0 test/metafield_test.rb
shopify_api-5.0.0 test/metafield_test.rb
shopify_api-4.13.0 test/metafield_test.rb
shopify_api-4.12.0 test/metafield_test.rb
shopify_api-4.11.0 test/metafield_test.rb
shopify_api-4.10.0 test/metafield_test.rb
shopify_api-4.9.1 test/metafield_test.rb
shopify_api-4.9.0 test/metafield_test.rb
shopify_api-4.8.0 test/metafield_test.rb
shopify_api-4.7.1 test/metafield_test.rb
shopify_api-4.7.0 test/metafield_test.rb