diff options
Diffstat (limited to 'activemodel/test/cases/serializers')
-rw-r--r-- | activemodel/test/cases/serializers/json_serialization_test.rb | 5 | ||||
-rwxr-xr-x | activemodel/test/cases/serializers/xml_serialization_test.rb | 12 |
2 files changed, 11 insertions, 6 deletions
diff --git a/activemodel/test/cases/serializers/json_serialization_test.rb b/activemodel/test/cases/serializers/json_serialization_test.rb index fd4d068354..9134c4980c 100644 --- a/activemodel/test/cases/serializers/json_serialization_test.rb +++ b/activemodel/test/cases/serializers/json_serialization_test.rb @@ -157,11 +157,8 @@ class JsonSerializationTest < ActiveModel::TestCase test "as_json should keep the default order in the hash" do json = @contact.as_json - keys = json.keys - %w(name age created_at awesome preferences).each_with_index do |field, index| - assert_equal keys.index(field), index - end + assert_equal %w(name age created_at awesome preferences), json.keys end test "from_json should work without a root (class attribute)" do diff --git a/activemodel/test/cases/serializers/xml_serialization_test.rb b/activemodel/test/cases/serializers/xml_serialization_test.rb index 90ddf8ff0c..99a9c1fe33 100755 --- a/activemodel/test/cases/serializers/xml_serialization_test.rb +++ b/activemodel/test/cases/serializers/xml_serialization_test.rb @@ -6,12 +6,12 @@ require 'ostruct' class Contact include ActiveModel::Serializers::Xml - attr_accessor :address, :friends + attr_accessor :address, :friends, :contact remove_method :attributes if method_defined?(:attributes) def attributes - instance_values.except("address", "friends") + instance_values.except("address", "friends", "contact") end end @@ -56,6 +56,9 @@ class XmlSerializationTest < ActiveModel::TestCase @contact.address.zip = 11111 @contact.address.apt_number = 35 @contact.friends = [Contact.new, Contact.new] + @related_contact = SerializableContact.new + @related_contact.name = "related" + @contact.contact = @related_contact end test "should serialize default root" do @@ -256,4 +259,9 @@ class XmlSerializationTest < ActiveModel::TestCase assert_match %r{<address>}, xml assert_match %r{<apt-number type="integer">}, xml end + + test "association with sti" do + xml = @contact.to_xml(include: :contact) + assert xml.include?(%(<contact type="SerializableContact">)) + end end |