diff options
author | Tobias Lütke <tobias.luetke@gmail.com> | 2007-07-09 22:07:39 +0000 |
---|---|---|
committer | Tobias Lütke <tobias.luetke@gmail.com> | 2007-07-09 22:07:39 +0000 |
commit | 187e1f85d0c871ba61e5bc3651a7ec2f657db8f9 (patch) | |
tree | c260f539da2ec6457aa732f3fb98c7926a80fe9f /activerecord/test | |
parent | cb2381696029ad839ecddad08afea061d07685fb (diff) | |
download | rails-187e1f85d0c871ba61e5bc3651a7ec2f657db8f9.tar.gz rails-187e1f85d0c871ba61e5bc3651a7ec2f657db8f9.tar.bz2 rails-187e1f85d0c871ba61e5bc3651a7ec2f657db8f9.zip |
Support for non heterogeneous arrays when serializing to xml. Unless guessable from array name the type name will be included as attribute
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7173 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/xml_serialization_test.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/activerecord/test/xml_serialization_test.rb b/activerecord/test/xml_serialization_test.rb index 807daddabb..f6e3d0dd9d 100644 --- a/activerecord/test/xml_serialization_test.rb +++ b/activerecord/test/xml_serialization_test.rb @@ -2,6 +2,7 @@ require 'abstract_unit' require 'fixtures/post' require 'fixtures/author' require 'fixtures/tagging' +require 'fixtures/comment' class Contact < ActiveRecord::Base # mock out self.columns so no pesky db is needed for these tests @@ -147,8 +148,8 @@ class DatabaseConnectedXmlSerializationTest < Test::Unit::TestCase def test_include_uses_association_name xml = authors(:david).to_xml :include=>:hello_posts, :indent => 0 assert_match %r{<hello-posts type="array">}, xml - assert_match %r{<post>}, xml - assert_match %r{<sti-post>}, xml + assert_match %r{<hello-post type="Post">}, xml + assert_match %r{<hello-post type="StiPost">}, xml end def test_methods_are_called_on_object @@ -171,4 +172,18 @@ class DatabaseConnectedXmlSerializationTest < Test::Unit::TestCase assert_match %r{^ <posts type="array"/>}, xml end + def test_should_has_many_array_elements_should_include_type_when_different_from_guessed_value + xml = authors(:david).to_xml :include=>:posts_with_comments, :indent => 2 + + assert Hash.from_xml(xml) + assert_match %r{^ <posts-with-comments type="array">}, xml + assert_match %r{^ <posts-with-comment type="Post">}, xml + assert_match %r{^ <posts-with-comment type="StiPost">}, xml + + types = Hash.from_xml(xml)['author']['posts_with_comments'].collect {|t| t['type'] } + assert types.include?('SpecialPost') + assert types.include?('Post') + assert types.include?('StiPost') + end + end
\ No newline at end of file |