Skip to content
This repository
Browse code

to_xml: the :methods option works on arrays of records. Closes #5845.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4909 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit d0696d764189996422c3dea649c388b7685a10e5 1 parent ad63005
Jeremy Kemper authored September 02, 2006
2  activerecord/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* to_xml: the :methods option works on arrays of records.  #5845 [Josh Starcher]
  4
+
3 5
 * Deprecation: update docs. #5998 [jakob@mentalized.net, Kevin Clark]
4 6
 
5 7
 * Add some XmlSerialization tests for ActiveRecord [Rick Olson]
2  activerecord/lib/active_record/xml_serialization.rb
@@ -160,7 +160,7 @@ def serializable_attributes
160 160
     end
161 161
 
162 162
     def serializable_method_attributes
163  
-      Array(options.delete(:methods)).collect { |name| MethodAttribute.new(name.to_s, @record) }
  163
+      Array(options[:methods]).collect { |name| MethodAttribute.new(name.to_s, @record) }
164 164
     end
165 165
 
166 166
 
6  activerecord/test/base_test.rb
@@ -1340,6 +1340,12 @@ def test_array_to_xml_including_has_many_association
1340 1340
     xml = [ topics(:first), topics(:second) ].to_xml(:indent => 0, :skip_instruct => true, :include => :replies)
1341 1341
     assert xml.include?(%(<replies><reply>))
1342 1342
   end
  1343
+
  1344
+  def test_array_to_xml_including_methods
  1345
+    xml = [ topics(:first), topics(:second) ].to_xml(:indent => 0, :skip_instruct => true, :methods => [ :topic_id ])
  1346
+    assert xml.include?(%(<topic-id type="integer">#{topics(:first).topic_id}</topic-id>))
  1347
+    assert xml.include?(%(<topic-id type="integer">#{topics(:second).topic_id}</topic-id>))
  1348
+  end
1343 1349
   
1344 1350
   def test_array_to_xml_including_has_one_association
1345 1351
     xml = [ companies(:first_firm), companies(:rails_core) ].to_xml(:indent => 0, :skip_instruct => true, :include => :account)
7  activerecord/test/fixtures/topic.rb
@@ -9,6 +9,11 @@ def parent
9 9
     Topic.find(parent_id)
10 10
   end
11 11
   
  12
+  # trivial method for testing Array#to_xml with :methods
  13
+  def topic_id
  14
+    id
  15
+  end
  16
+
12 17
   protected
13 18
     def default_written_on
14 19
       self.written_on = Time.now unless attribute_present?("written_on")
@@ -17,4 +22,4 @@ def default_written_on
17 22
     def destroy_children
18 23
       self.class.delete_all "parent_id = #{id}"
19 24
     end
20  
-end
  25
+end

0 notes on commit d0696d7

Please sign in to comment.
Something went wrong with that request. Please try again.