Permalink
Browse files

Re-define empty? for errors to check if the values inside the Ordered…

…Hash are empty rather than the OrderedHash itself. [#4356 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 9446376 commit d748cc3cd07c6931e5ebc5242f268f1f7ec3d906 @radar radar committed with josevalim Apr 9, 2010
Showing with 11 additions and 0 deletions.
  1. +5 −0 activemodel/lib/active_model/errors.rb
  2. +6 −0 activemodel/test/cases/validations_test.rb
View
5 activemodel/lib/active_model/errors.rb
@@ -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")
View
6 activemodel/test/cases/validations_test.rb
@@ -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|

0 comments on commit d748cc3

Please sign in to comment.