diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-19 22:32:39 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-19 22:32:39 +0000 |
commit | c87d242bf7b0f75800926c3a8cf23bb43667c9dd (patch) | |
tree | f80d29463400c06fe1410d9bfcae47b76ffee9ea | |
parent | c97f329b2a76439cd4fe71debdd64c71e9890b48 (diff) | |
download | rails-c87d242bf7b0f75800926c3a8cf23bb43667c9dd.tar.gz rails-c87d242bf7b0f75800926c3a8cf23bb43667c9dd.tar.bz2 rails-c87d242bf7b0f75800926c3a8cf23bb43667c9dd.zip |
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
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/conversions.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 11 |
3 files changed, 15 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 55f57b1180..58bfefe90d 100644 --- a/activesupport/CHANGELOG +++ b/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] diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 07d50df6ba..4e076dce6e 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -99,6 +99,8 @@ module ActiveSupport #:nodoc: end end end + + yield options[:builder] if block_given? end end diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 63caed7d99..813e23af5f 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -342,6 +342,17 @@ class HashToXmlTest < Test::Unit::TestCase 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) |