提交 272c504f 编写于 作者: J Joshua Peek

Dasherize XML root by default to avoid invalid tags...

Dasherize XML root by default to avoid invalid tags "<admin/posts>...</admin/posts>" [#2875 state:resolved]
上级 c39151a8
......@@ -90,7 +90,7 @@ def builder
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
......
......@@ -9,6 +9,11 @@ def attributes
end
end
module Admin
class Contact < ::Contact
end
end
class XmlSerializationTest < ActiveModel::TestCase
def setup
@contact = Contact.new
......@@ -25,6 +30,12 @@ def setup
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
......
class Contact
attr_accessor :name, :age, :created_at, :awesome, :preferences
def initialize(options = {})
options.each { |name, value| send("#{name}=", value) }
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册