diff options
author | José Valim <jose.valim@gmail.com> | 2009-07-28 09:00:33 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-07-28 09:00:33 +0200 |
commit | d9aae2b56e64a4f417eaffa99e10cca274e928e7 (patch) | |
tree | 8438f6f784df9b252c0f834bc7cb9c369103d4cd /activemodel/test/cases/serializeration/xml_serialization_test.rb | |
parent | 5025ae610f89989f3e15241ec7065e3d443614d9 (diff) | |
parent | 9533e0eca76b1df68a90e1ebe395d7b6a59d8e91 (diff) | |
download | rails-d9aae2b56e64a4f417eaffa99e10cca274e928e7.tar.gz rails-d9aae2b56e64a4f417eaffa99e10cca274e928e7.tar.bz2 rails-d9aae2b56e64a4f417eaffa99e10cca274e928e7.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activemodel/test/cases/serializeration/xml_serialization_test.rb')
-rw-r--r-- | activemodel/test/cases/serializeration/xml_serialization_test.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/activemodel/test/cases/serializeration/xml_serialization_test.rb b/activemodel/test/cases/serializeration/xml_serialization_test.rb index e459f6433a..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 @@ -82,4 +93,16 @@ class XmlSerializationTest < ActiveModel::TestCase test "should serialize yaml" do assert_match %r{<preferences type=\"yaml\">--- \n:gem: ruby\n</preferences>}, @contact.to_xml end + + test "should call proc on object" do + proc = Proc.new { |options| options[:builder].tag!('nationality', 'unknown') } + xml = @contact.to_xml(:procs => [ proc ]) + assert_match %r{<nationality>unknown</nationality>}, xml + end + + test 'should supply serializable to second proc argument' do + proc = Proc.new { |options, record| options[:builder].tag!('name-reverse', record.name.reverse) } + xml = @contact.to_xml(:procs => [ proc ]) + assert_match %r{<name-reverse>kcats noraa</name-reverse>}, xml + end end |