提交 d748cc3c 编写于 作者: R Ryan Bigg 提交者: José Valim

Re-define empty? for errors to check if the values inside the OrderedHash are...

Re-define empty? for errors to check if the values inside the OrderedHash are empty rather than the OrderedHash itself. [#4356 state:resolved]
Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 94463764
......@@ -142,6 +142,11 @@ def count
to_a.size
end
# Returns true if there are any errors, false if not.
def empty?
all? { |k, v| v && v.empty? }
end
# Returns an xml formatted representation of the Errors hash.
#
# p.errors.add(:name, "can't be blank")
......
......@@ -97,6 +97,12 @@ def test_errors_on_base
assert_equal 2, r.errors.count
end
def test_errors_empty_after_errors_on_check
t = Topic.new
assert t.errors[:id].empty?
assert t.errors.empty?
end
def test_validates_each
hits = 0
Topic.validates_each(:title, :content, [:title, :content]) do |record, attr|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册