diff options
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/xml_serialization.rb | 4 | ||||
-rw-r--r-- | activerecord/test/xml_serialization_test.rb | 9 |
3 files changed, 12 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index e017ade603..9190fcbb7d 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Use association name for the wrapper element when using .to_xml. Previous behaviour lead to non-deterministic situations with STI and polymorphic associations. [Koz, jstrachan] + * Improve performance of calling .create on has_many :through associations. [evan] * Improved cloning performance by relying less on exception raising #8159 [Blaine] diff --git a/activerecord/lib/active_record/xml_serialization.rb b/activerecord/lib/active_record/xml_serialization.rb index e256135205..c3a39fc49d 100644 --- a/activerecord/lib/active_record/xml_serialization.rb +++ b/activerecord/lib/active_record/xml_serialization.rb @@ -204,11 +204,11 @@ module ActiveRecord #:nodoc: when :has_many, :has_and_belongs_to_many records = @record.send(association).to_a unless records.empty? - tag = records.first.class.to_s.underscore.pluralize + tag = association.to_s tag = tag.dasherize if dasherize? builder.tag!(tag) do - records.each { |r| r.to_xml(opts.merge(:root => association.to_s.singularize)) } + records.each { |r| r.to_xml(opts.merge(:root=>r.class.to_s.underscore)) } end end when :has_one, :belongs_to diff --git a/activerecord/test/xml_serialization_test.rb b/activerecord/test/xml_serialization_test.rb index 752a0021a9..b32a55a786 100644 --- a/activerecord/test/xml_serialization_test.rb +++ b/activerecord/test/xml_serialization_test.rb @@ -133,7 +133,8 @@ end class DatabaseConnectedXmlSerializationTest < Test::Unit::TestCase fixtures :authors, :posts # to_xml used to mess with the hash the user provided which - # caused the builder to be reused + # caused the builder to be reused. This meant the document kept + # getting appended to. def test_passing_hash_shouldnt_reuse_builder options = {:include=>:posts} david = authors(:david) @@ -141,4 +142,10 @@ class DatabaseConnectedXmlSerializationTest < Test::Unit::TestCase second_xml_size = david.to_xml(options).size assert_equal first_xml_size, second_xml_size end + + + def test_include_uses_association_name + xml = authors(:david).to_xml :include=>:hello_posts, :indent=>0 + assert(xml.include?(%(<hello_posts><post>)) || xml.include?(%(</post></hello-posts>))) + end end
\ No newline at end of file |