aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb5
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb11
3 files changed, 17 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 610d79fe29..81f78bb9a7 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Array#to_xml yields the builder just like Hash and ActiveRecord::Base. #8472 [seth]
+
* Date, Time, and DateTime support formatting blocks in addition to strftime strings. Introduce :long_ordinal format, e.g. "February 21st, 2005". #8191 [Coda Hale]
* Document Object#blank?. #6491 [Chris Mear]
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index 51ac83294c..a4d056e81c 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -63,7 +63,10 @@ module ActiveSupport #:nodoc:
opts = options.merge({ :root => children })
- options[:builder].tag!(root) { each { |e| e.to_xml(opts.merge!({ :skip_instruct => true })) } }
+ options[:builder].tag!(root) {
+ yield options[:builder] if block_given?
+ each { |e| e.to_xml(opts.merge!({ :skip_instruct => true })) }
+ }
end
end
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index 26bc232b81..e5ca4c424f 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -179,4 +179,15 @@ class ArrayToXmlTests < Test::Unit::TestCase
assert_match(/^<\?xml [^>]*/, xml)
assert_equal 0, xml.rindex(/<\?xml /)
end
+
+ def test_to_xml_with_block
+ xml = [
+ { :name => "David", :age => 26, :age_in_millis => 820497600000 },
+ { :name => "Jason", :age => 31, :age_in_millis => BigDecimal.new('1.0') }
+ ].to_xml(:skip_instruct => true, :indent => 0) do |xml|
+ xml.count 2
+ end
+
+ assert xml.include?(%(<count>2</count>)), xml
+ end
end