variant_test.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. require 'test_helper'
  2. class VariantTest < Test::Unit::TestCase
  3. def test_get_variants
  4. fake "products/632910392/variants", :method => :get, :body => load_fixture('variants')
  5. variants = ShopifyAPI::Variant.find(:all, :params => { :product_id => 632910392 })
  6. assert_equal variants.map(&:id).sort, [39072856, 49148385, 457924702, 808950810]
  7. end
  8. def test_get_variant_namespaced
  9. fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
  10. v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
  11. assert_equal 632910392, v.product_id
  12. end
  13. def test_get_variant
  14. fake "variants/808950810", :method => :get, :body => load_fixture('variant')
  15. v = ShopifyAPI::Variant.find(808950810)
  16. assert_equal 632910392, v.product_id
  17. end
  18. def test_product_id_should_be_accessible_if_via_product_endpoint
  19. fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
  20. v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
  21. assert_equal 632910392, v.product_id
  22. end
  23. def test_product_id_should_be_accessible_if_via_variant_endpoint
  24. fake "variants/808950810", :method => :get, :body => load_fixture('variant')
  25. v = ShopifyAPI::Variant.find(808950810)
  26. assert_equal 632910392, v.product_id
  27. end
  28. def test_delete_variant
  29. fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
  30. fake "products/632910392/variants/808950810", :method => :delete, :body => 'destroyed'
  31. v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
  32. assert v.destroy
  33. end
  34. end