提交 d0696d76 编写于 作者: J Jeremy Kemper

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
上级 ad63005c
*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]
......
......@@ -160,7 +160,7 @@ def serializable_attributes
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
......
......@@ -1340,6 +1340,12 @@ def test_array_to_xml_including_has_many_association
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)
......
......@@ -9,6 +9,11 @@ def parent
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 @@ def default_written_on
def destroy_children
self.class.delete_all "parent_id = #{id}"
end
end
\ No newline at end of file
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册