Permalink
Browse files

Dasherize XML root by default to avoid invalid tags "<admin/posts>...…

…</admin/posts>" [#2875 state:resolved]
  • Loading branch information...
1 parent c39151a commit 272c504f919d187603915059572e37d3a78329cc @josh josh committed Jul 23, 2009
@@ -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
@@ -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

0 comments on commit 272c504

Please sign in to comment.