order_test.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. require 'test_helper'
  2. class OrderTest < Test::Unit::TestCase
  3. def setup
  4. ActiveResource::Base.site = "http://localhost"
  5. end
  6. context "Order" do
  7. context "#note_attributes" do
  8. should "be loaded correctly from order xml" do
  9. order_xml = <<-XML
  10. <?xml version="1.0" encoding="UTF-8"?>
  11. <order>
  12. <note-attributes type="array">
  13. <note-attribute>
  14. <name>size</name>
  15. <value>large</value>
  16. </note-attribute>
  17. </note-attributes>
  18. </order>
  19. XML
  20. order = ShopifyAPI::Order.new(Hash.from_xml(order_xml)["order"])
  21. assert_equal 1, order.note_attributes.size
  22. note_attribute = order.note_attributes.first
  23. assert_equal "size", note_attribute.name
  24. assert_equal "large", note_attribute.value
  25. end
  26. should "be able to add note attributes to an order" do
  27. order = ShopifyAPI::Order.new
  28. order.note_attributes = []
  29. order.note_attributes << ShopifyAPI::NoteAttribute.new(:name => "color", :value => "blue")
  30. order_xml = Hash.from_xml(order.to_xml)
  31. assert note_attributes = order_xml["order"]["note_attributes"]
  32. assert_instance_of Array, note_attributes
  33. attribute = note_attributes.first
  34. assert_equal "color", attribute["name"]
  35. assert_equal "blue", attribute["value"]
  36. end
  37. end
  38. end
  39. end