diff options
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/xml_serialization.rb | 2 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 6 | ||||
-rwxr-xr-x | activerecord/test/fixtures/topic.rb | 7 |
4 files changed, 15 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 9b633d5674..6e661787ef 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* to_xml: the :methods option works on arrays of records. #5845 [Josh Starcher] + * Deprecation: update docs. #5998 [jakob@mentalized.net, Kevin Clark] * Add some XmlSerialization tests for ActiveRecord [Rick Olson] diff --git a/activerecord/lib/active_record/xml_serialization.rb b/activerecord/lib/active_record/xml_serialization.rb index 273f3003fb..8d1dda5875 100644 --- a/activerecord/lib/active_record/xml_serialization.rb +++ b/activerecord/lib/active_record/xml_serialization.rb @@ -160,7 +160,7 @@ module ActiveRecord #:nodoc: end def serializable_method_attributes - Array(options.delete(:methods)).collect { |name| MethodAttribute.new(name.to_s, @record) } + Array(options[:methods]).collect { |name| MethodAttribute.new(name.to_s, @record) } end diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index b917e43278..18c5b50006 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1340,6 +1340,12 @@ class BasicsTest < Test::Unit::TestCase xml = [ topics(:first), topics(:second) ].to_xml(:indent => 0, :skip_instruct => true, :include => :replies) assert xml.include?(%(<replies><reply>)) end + + def test_array_to_xml_including_methods + xml = [ topics(:first), topics(:second) ].to_xml(:indent => 0, :skip_instruct => true, :methods => [ :topic_id ]) + assert xml.include?(%(<topic-id type="integer">#{topics(:first).topic_id}</topic-id>)) + assert xml.include?(%(<topic-id type="integer">#{topics(:second).topic_id}</topic-id>)) + end def test_array_to_xml_including_has_one_association xml = [ companies(:first_firm), companies(:rails_core) ].to_xml(:indent => 0, :skip_instruct => true, :include => :account) diff --git a/activerecord/test/fixtures/topic.rb b/activerecord/test/fixtures/topic.rb index 9b20f02cb0..d7cd52e33e 100755 --- a/activerecord/test/fixtures/topic.rb +++ b/activerecord/test/fixtures/topic.rb @@ -9,6 +9,11 @@ class Topic < ActiveRecord::Base Topic.find(parent_id) end + # trivial method for testing Array#to_xml with :methods + def topic_id + id + end + protected def default_written_on self.written_on = Time.now unless attribute_present?("written_on") @@ -17,4 +22,4 @@ class Topic < ActiveRecord::Base def destroy_children self.class.delete_all "parent_id = #{id}" end -end
\ No newline at end of file +end |