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: José Valim <jose.valim@gmail.com>
This commit is contained in:
Ryan Bigg 2010-04-10 00:48:24 +10:00 committed by José Valim
parent 944637648c
commit d748cc3cd0
2 changed files with 11 additions and 0 deletions

@ -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|