diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/serializers/xml_serializer.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/serialization_test.rb | 7 | ||||
-rw-r--r-- | 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 ed5964d923..b2d4a48945 100644 --- a/activerecord/lib/active_record/serializers/xml_serializer.rb +++ b/activerecord/lib/active_record/serializers/xml_serializer.rb @@ -197,7 +197,7 @@ module ActiveRecord #:nodoc: # 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 8841694271..8c385af97c 100644 --- a/activerecord/test/cases/serialization_test.rb +++ b/activerecord/test/cases/serialization_test.rb @@ -44,4 +44,11 @@ class SerializationTest < ActiveRecord::TestCase 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('<?xml '), 0 + assert_nil @serialized.index('<?xml ', 1) + end end diff --git a/activerecord/test/models/contact.rb b/activerecord/test/models/contact.rb index dbfa57bf49..975a885331 100644 --- a/activerecord/test/models/contact.rb +++ b/activerecord/test/models/contact.rb @@ -13,4 +13,6 @@ class Contact < ActiveRecord::Base column :preferences, :string serialize :preferences -end
\ No newline at end of file + + belongs_to :alternative, :class_name => 'Contact' +end |