Permalink
Browse files

Merge pull request #2893 from dmathieu/errors_has_key

add has_key? to ActiveModel::Errors
  • Loading branch information...
2 parents ef14a0e + e0335e2 commit 51652a4773ab19c866ea1781b39f46f17faa68f3 @tenderlove tenderlove committed Sep 6, 2011
Showing with 7 additions and 0 deletions.
  1. +1 −0 activemodel/lib/active_model/errors.rb
  2. +6 −0 activemodel/test/cases/errors_test.rb
@@ -88,6 +88,7 @@ def clear
def include?(error)
(v = messages[error]) && v.any?
end
+ alias :has_key? :include?
# Get messages for +key+
def get(key)
@@ -33,6 +33,12 @@ def test_include?
assert errors.include?(:foo), 'errors should include :foo'
end
+ def test_has_key?
+ errors = ActiveModel::Errors.new(self)
+ errors[:foo] = 'omg'
+ assert errors.has_key?(:foo), 'errors should have key :foo'
+ end
+
test "should return true if no errors" do
person = Person.new
person.errors[:foo]

0 comments on commit 51652a4

Please sign in to comment.