提交 0990a135 编写于 作者: A Akira Matsuda 提交者: Jeremy Kemper

Ensure validation errors to be ordered in declared order

[#2301 state:committed milestone:2.3.5]
Signed-off-by: NJeremy Kemper <jeremy@bitsweat.net>
上级 68b2b730
require 'active_support/core_ext/string/inflections'
require 'active_support/ordered_hash'
module ActiveModel
class Errors < Hash
class Errors < ActiveSupport::OrderedHash
include DeprecatedErrorMethods
def initialize(base)
......
......@@ -141,6 +141,22 @@ def test_validation_order
t = Topic.new("title" => "")
assert !t.valid?
assert_equal "can't be blank", t.errors["title"].first
Topic.validates_presence_of :title, :author_name
Topic.validate {|topic| topic.errors.add('author_email_address', 'will never be valid')}
Topic.validates_length_of :title, :content, :minimum => 2
t = Topic.new :title => ''
assert !t.valid?
assert_equal :title, key = t.errors.keys.first
assert_equal "can't be blank", t.errors[key].first
assert_equal 'is too short (minimum is 2 characters)', t.errors[key].second
assert_equal :author_name, key = t.errors.keys.second
assert_equal "can't be blank", t.errors[key].first
assert_equal :author_email_address, key = t.errors.keys.third
assert_equal 'will never be valid', t.errors[key].first
assert_equal :content, key = t.errors.keys.fourth
assert_equal 'is too short (minimum is 2 characters)', t.errors[key].first
end
def test_invalid_should_be_the_opposite_of_valid
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册