Permalink
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...
1 parent dae2473 commit a84e9b4f31ac39b0e466f8f0efc507a52dbb02c0 @yaroslav yaroslav committed with josevalim Dec 27, 2009
@@ -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])
@@ -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

0 comments on commit a84e9b4

Please sign in to comment.