From 8792b8f2f545ff5d630ef95478076bd0b9610c10 Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Mon, 28 Dec 2009 01:58:14 +0300 Subject: [PATCH] Fix Array#to_xml to produce valid markup when working with namespaced classes --- .../active_support/core_ext/array/conversions.rb | 2 +- activesupport/test/core_ext/array_ext_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 779743b..579b18c 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -164,7 +164,7 @@ module ActiveSupport #:nodoc: 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]) diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index fe48d39..7e8a8b3 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -300,6 +300,16 @@ class ArrayToXmlTests < Test::Unit::TestCase assert xml.include?(%(2)), xml end + + class Namespaced < Hash + end + def test_to_xml_with_namespaced_classes + xml = [ + Namespaced.new :name => "David" + ].to_xml + + assert_match(/