diff options
-rw-r--r-- | activemodel/lib/active_model/serializers/xml.rb | 2 | ||||
-rw-r--r-- | activemodel/test/cases/serializeration/xml_serialization_test.rb | 11 | ||||
-rw-r--r-- | activemodel/test/models/contact.rb | 4 |
3 files changed, 16 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb index 8137300479..4508a39347 100644 --- a/activemodel/lib/active_model/serializers/xml.rb +++ b/activemodel/lib/active_model/serializers/xml.rb @@ -90,7 +90,7 @@ module ActiveModel end def root - root = (options[:root] || @serializable.class.to_s.underscore).to_s + root = (options[:root] || @serializable.class.model_name.singular).to_s reformat_name(root) end diff --git a/activemodel/test/cases/serializeration/xml_serialization_test.rb b/activemodel/test/cases/serializeration/xml_serialization_test.rb index 0737c4f2f9..428e5a6bd1 100644 --- a/activemodel/test/cases/serializeration/xml_serialization_test.rb +++ b/activemodel/test/cases/serializeration/xml_serialization_test.rb @@ -9,6 +9,11 @@ class Contact end end +module Admin + class Contact < ::Contact + end +end + class XmlSerializationTest < ActiveModel::TestCase def setup @contact = Contact.new @@ -25,6 +30,12 @@ class XmlSerializationTest < ActiveModel::TestCase assert_match %r{</contact>$}, @xml end + test "should serialize namespaced root" do + @xml = Admin::Contact.new(@contact.attributes).to_xml + assert_match %r{^<admin-contact>}, @xml + assert_match %r{</admin-contact>$}, @xml + end + test "should serialize default root with namespace" do @xml = @contact.to_xml :namespace => "http://xml.rubyonrails.org/contact" assert_match %r{^<contact xmlns="http://xml.rubyonrails.org/contact">}, @xml diff --git a/activemodel/test/models/contact.rb b/activemodel/test/models/contact.rb index 7d69c91996..f9fb0af027 100644 --- a/activemodel/test/models/contact.rb +++ b/activemodel/test/models/contact.rb @@ -1,3 +1,7 @@ class Contact attr_accessor :name, :age, :created_at, :awesome, :preferences + + def initialize(options = {}) + options.each { |name, value| send("#{name}=", value) } + end end |