Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix Array#to_xml to produce valid markup when working with namespaced…

… classes [#3624 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit a84e9b4f31ac39b0e466f8f0efc507a52dbb02c0 1 parent dae2473
@yaroslav yaroslav authored josevalim committed
View
2  activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -164,7 +164,7 @@ def to_xml(options = {})
require 'builder' unless defined?(Builder)
options = options.dup
- options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records"
+ options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize.tr('/', '-') : "records"
options[:children] ||= options[:root].singularize
options[:indent] ||= 2
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
View
10 activesupport/test/core_ext/array_ext_test.rb
@@ -300,6 +300,16 @@ def test_to_xml_with_block
assert xml.include?(%(<count>2</count>)), xml
end
+
+ class Namespaced < Hash
+ end
+ def test_to_xml_with_namespaced_classes
+ xml = [
+ Namespaced.new :name => "David"
+ ].to_xml
+
+ assert_match(/<array\-to\-xml\-tests\-namespaceds/, xml)
+ end
def test_to_xml_with_empty
xml = [].to_xml
Please sign in to comment.
Something went wrong with that request. Please try again.