提交 010a10f3 编写于 作者: J Jamis Buck

Add ActiveRecord::Errors#to_xml


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4243 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 1f80f540
*SVN*
* Add ActiveRecord::Errors#to_xml [Jamis Buck]
* Properly quote index names in migrations (closes #4764) [John Long]
* Fix the HasManyAssociation#count method so it uses the new ActiveRecord::Base#count syntax, while maintaining backwards compatibility. [Rick]
......
......@@ -156,6 +156,18 @@ def size
alias_method :count, :size
alias_method :length, :size
# Return an XML representation of this error object.
def to_xml(options={})
options[:root] ||= "errors"
options[:indent] ||= 2
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
options[:builder].instruct! unless options.delete(:skip_instruct)
options[:builder].errors do |e|
full_messages.each { |msg| e.error(msg) }
end
end
end
......
......@@ -995,6 +995,15 @@ def test_validates_associated_missing
r.topic = Topic.find :first
assert r.valid?
end
def test_errors_to_xml
r = Reply.new :title => "Wrong Create"
assert !r.valid?
xml = r.errors.to_xml(:skip_instruct => true)
assert_equal "<errors>", xml.first(8)
assert xml.include?("<error>Title is Wrong Create</error>")
assert xml.include?("<error>Content Empty</error>")
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册