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:
parent
944637648c
commit
d748cc3cd0
@ -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|
|
||||
|
Loading…
Reference in New Issue
Block a user