From 60504e62c8e2f5e137a0ac82aed67a6c0fe42447 Mon Sep 17 00:00:00 2001 From: Lawrence Pit Date: Fri, 30 Apr 2010 10:39:52 +1000 Subject: [PATCH] to_xml with :include should skip_instruct on the included records [#4506 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../lib/active_record/serializers/xml_serializer.rb | 2 +- activerecord/test/cases/serialization_test.rb | 7 +++++++ activerecord/test/models/contact.rb | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb index ed5964d92303..b2d4a4894507 100644 --- a/activerecord/lib/active_record/serializers/xml_serializer.rb +++ b/activerecord/lib/active_record/serializers/xml_serializer.rb @@ -197,7 +197,7 @@ def add_includes # TODO This can likely be cleaned up to simple use ActiveSupport::XmlMini.to_tag as well. def add_associations(association, records, opts) association_name = association.to_s.singularize - merged_options = options.merge(opts).merge!(:root => association_name) + merged_options = options.merge(opts).merge!(:root => association_name, :skip_instruct => true) if records.is_a?(Enumerable) tag = ActiveSupport::XmlMini.rename_key(association.to_s, options) diff --git a/activerecord/test/cases/serialization_test.rb b/activerecord/test/cases/serialization_test.rb index 88416942717d..8c385af97cf1 100644 --- a/activerecord/test/cases/serialization_test.rb +++ b/activerecord/test/cases/serialization_test.rb @@ -44,4 +44,11 @@ def test_serialize_should_allow_attribute_except_filtering assert_equal @contact_attributes[:awesome], contact.awesome, "For #{format}" end end + + def test_serialize_should_xml_skip_instruct_for_included_records + @contact.alternative = Contact.new(:name => 'Copa Cabana') + @serialized = @contact.to_xml(:include => [ :alternative ]) + assert_equal @serialized.index(' 'Contact' +end