From c39151a84768397d3bb025c6e8f877eac59ebbf9 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Wed, 22 Jul 2009 20:47:15 -0500 Subject: 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 --- .../test/cases/serializeration/xml_serialization_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activemodel/test/cases/serializeration/xml_serialization_test.rb') 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{--- \n:gem: ruby\n}, @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{unknown}, 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{kcats noraa}, xml + end end -- cgit v1.2.3