提交 5b2be629 编写于 作者: T Tobias Lütke

Make [7169] work as expected with indented XML.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7171 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 049b1440
......@@ -207,8 +207,12 @@ def add_includes
records = @record.send(association).to_a
tag = association.to_s
tag = tag.dasherize if dasherize?
builder.tag!(tag, :type => :array) do
records.each { |r| r.to_xml(opts.merge(:root=>r.class.to_s.underscore)) }
if records.empty?
builder.tag!(tag, :type => :array)
else
builder.tag!(tag, :type => :array) do
records.each { |r| r.to_xml(opts.merge(:root=>r.class.to_s.underscore)) }
end
end
when :has_one, :belongs_to
if record = @record.send(association)
......
......@@ -165,9 +165,10 @@ def test_should_not_call_methods_on_associations_that_dont_respond
def test_should_include_empty_has_many_as_empty_array
authors(:david).posts.delete_all
xml = authors(:david).to_xml :include=>:posts, :indent => 0
xml = authors(:david).to_xml :include=>:posts, :indent => 2
assert_match %r{<posts type="array"></posts>}, xml
assert_equal [], Hash.from_xml(xml)['author']['posts']
assert_match %r{^ <posts type="array"/>}, xml
end
end
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册