Ticket #8308: xml_serialize.patch
| File xml_serialize.patch, 2.0 kB (added by mbbx6spp, 2 years ago) |
|---|
-
test/core_ext/array_ext_test.rb
old new 1 1 require File.dirname(__FILE__) + '/../abstract_unit' 2 2 require 'bigdecimal' 3 3 4 module TestNamespace 5 class Model 6 attr_accessor :id, :name 7 8 def initialize(id, name) 9 @id = id 10 @name = name 11 end 12 13 # hacked up to_xml for test purposes 14 # basically ignoring both options and block parameters 15 def to_xml(options = {}, &block) 16 "<test-namespace:model><id>#{@id}</id><name>#{@name}</name></test-namespace:model>" 17 end 18 end 19 end 20 4 21 class ArrayExtToParamTests < Test::Unit::TestCase 5 22 def test_string_array 6 23 assert_equal '', %w().to_param … … 179 196 assert_match(/^<\?xml [^>]*/, xml) 180 197 assert_equal 0, xml.rindex(/<\?xml /) 181 198 end 199 200 def test_to_xml_with_namespaced_class 201 xml = [TestNamespace::Model.new(1, 'MyName')].to_xml(:skip_instruct => true) 202 assert_match(/<test-namespace:models>/, xml) 203 assert_match(/<\/test-namespace:models>/, xml) 204 end 182 205 end -
lib/active_support/core_ext/array/conversions.rb
old new 47 47 def to_xml(options = {}) 48 48 raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml } 49 49 50 options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore. pluralize : "records"50 options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.gsub(/\//, ':').pluralize : "records" 51 51 options[:children] ||= options[:root].singularize 52 52 options[:indent] ||= 2 53 53 options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])