aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/serializeration/xml_serialization_test.rb
diff options
context:
space:
mode:
authorJohn Maxwell <johnmaxwell@gmail.com>2009-07-22 20:47:15 -0500
committerJoshua Peek <josh@joshpeek.com>2009-07-22 20:47:15 -0500
commitc39151a84768397d3bb025c6e8f877eac59ebbf9 (patch)
treea4e34e773ff2629abfab91925ed6cd3a2685408e /activemodel/test/cases/serializeration/xml_serialization_test.rb
parent9d7aae710384fb5f04129c35b86c5ea5fb9d83a9 (diff)
downloadrails-c39151a84768397d3bb025c6e8f877eac59ebbf9.tar.gz
rails-c39151a84768397d3bb025c6e8f877eac59ebbf9.tar.bz2
rails-c39151a84768397d3bb025c6e8f877eac59ebbf9.zip
Patch to ActiveModel's (and ActiveRecord, by association) XML serialization: If two parameters are present in Procs supplied to to_xml's :procs option, the model being serialized will be passed as the second argument [#2373 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activemodel/test/cases/serializeration/xml_serialization_test.rb')
-rw-r--r--activemodel/test/cases/serializeration/xml_serialization_test.rb12
1 files changed, 12 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..0737c4f2f9 100644
--- a/activemodel/test/cases/serializeration/xml_serialization_test.rb
+++ b/activemodel/test/cases/serializeration/xml_serialization_test.rb
@@ -82,4 +82,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