Skip to content

Commit

Permalink
Add the type="array" moniker to has_many / has_and_belongs_to_many as…
Browse files Browse the repository at this point in the history
…sociations upon serialization.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7144 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
Tobias Lütke committed Jun 27, 2007
1 parent 80d539b commit 817d5d4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/xml_serialization.rb
Expand Up @@ -207,7 +207,7 @@ def add_includes
tag = association.to_s
tag = tag.dasherize if dasherize?

builder.tag!(tag) do
builder.tag!(tag, :type => :array) do
records.each { |r| r.to_xml(opts.merge(:root=>r.class.to_s.underscore)) }
end
end
Expand Down
8 changes: 4 additions & 4 deletions activerecord/test/base_test.rb
Expand Up @@ -1563,13 +1563,13 @@ def test_to_xml_skipping_attributes
def test_to_xml_including_has_many_association
xml = topics(:first).to_xml(:indent => 0, :skip_instruct => true, :include => :replies, :except => :replies_count)
assert_equal "<topic>", xml.first(7)
assert xml.include?(%(<replies><reply>))
assert xml.include?(%(<replies type="array"><reply>))
assert xml.include?(%(<title>The Second Topic's of the day</title>))
end

def test_array_to_xml_including_has_many_association
xml = [ topics(:first), topics(:second) ].to_xml(:indent => 0, :skip_instruct => true, :include => :replies)
assert xml.include?(%(<replies><reply>))
assert xml.include?(%(<replies type="array"><reply>))
end

def test_array_to_xml_including_methods
Expand Down Expand Up @@ -1603,7 +1603,7 @@ def test_to_xml_including_multiple_associations
xml = companies(:first_firm).to_xml(:indent => 0, :skip_instruct => true, :include => [ :clients, :account ])
assert_equal "<firm>", xml.first(6)
assert xml.include?(%(<account>))
assert xml.include?(%(<clients><client>))
assert xml.include?(%(<clients type="array"><client>))
end

def test_to_xml_including_multiple_associations_with_options
Expand All @@ -1614,7 +1614,7 @@ def test_to_xml_including_multiple_associations_with_options

assert_equal "<firm>", xml.first(6)
assert xml.include?(%(<client><name>Summit</name></client>))
assert xml.include?(%(<clients><client>))
assert xml.include?(%(<clients type="array"><client>))
end

def test_to_xml_including_methods
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/xml_serialization_test.rb
Expand Up @@ -146,7 +146,7 @@ def test_passing_hash_shouldnt_reuse_builder

def test_include_uses_association_name
xml = authors(:david).to_xml :include=>:hello_posts, :indent=>0
assert_match %r{<hello-posts>}, xml
assert_match %r{<hello-posts type="array">}, xml
assert_match %r{<post>}, xml
assert_match %r{<sti-post>}, xml
end
Expand Down

0 comments on commit 817d5d4

Please sign in to comment.