Permalink
Browse files

Added yielding of builder in Hash#to_xml [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6540 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent c97f329 commit c87d242bf7b0f75800926c3a8cf23bb43667c9dd @dhh dhh committed Apr 19, 2007
View
2 activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added yielding of builder in Hash#to_xml [DHH]
+
* Hash#with_indifferent_access now also converts hashes kept in arrays to indifferent access (makes it easier to treat HTML and XML parameters the same) [DHH]
* Hash#to_xml supports YAML attributes. #7502 [jonathan]
View
2 activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -99,6 +99,8 @@ def to_xml(options = {})
end
end
end
+
+ yield options[:builder] if block_given?
end
end
View
11 activesupport/test/core_ext/hash_ext_test.rb
@@ -342,6 +342,17 @@ def test_one_level_with_skipping_types
assert xml.include?(%(<age nil="true"></age>))
end
+ def test_one_level_with_yielding
+ xml = { :name => "David", :street => "Paulina" }.to_xml(@xml_options) do |xml|
+ xml.creator("Rails")
+ end
+
+ assert_equal "<person>", xml.first(8)
+ assert xml.include?(%(<street>Paulina</street>))
+ assert xml.include?(%(<name>David</name>))
+ assert xml.include?(%(<creator>Rails</creator>))
+ end
+
def test_two_levels
xml = { :name => "David", :address => { :street => "Paulina" } }.to_xml(@xml_options)
assert_equal "<person>", xml.first(8)

0 comments on commit c87d242

Please sign in to comment.