Skip to content

Commit

Permalink
to_xml with :include should skip_instruct on the included records [ra…
Browse files Browse the repository at this point in the history
…ils#4506 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
lawrencepit authored and josevalim committed Apr 30, 2010
1 parent a003a39 commit 60504e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions activerecord/test/cases/serialization_test.rb
Expand Up @@ -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('<?xml '), 0
assert_nil @serialized.index('<?xml ', 1)
end
end
4 changes: 3 additions & 1 deletion activerecord/test/models/contact.rb
Expand Up @@ -13,4 +13,6 @@ def self.column(name, sql_type = nil, options = {})
column :preferences, :string

serialize :preferences
end

belongs_to :alternative, :class_name => 'Contact'
end

0 comments on commit 60504e6

Please sign in to comment.