Skip to content

Commit

Permalink
Re-define empty? for errors to check if the values inside the Ordered…
Browse files Browse the repository at this point in the history
…Hash are empty rather than the OrderedHash itself. [#4356 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
radar authored and josevalim committed Apr 10, 2010
1 parent 9446376 commit d748cc3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions activemodel/lib/active_model/errors.rb
Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions activemodel/test/cases/validations_test.rb
Expand Up @@ -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|
Expand Down

0 comments on commit d748cc3

Please sign in to comment.