Permalink
Browse files

add has_key? to ActiveModel::Errors

  • Loading branch information...
1 parent ef14a0e commit e0335e2ccbdbbd14715877c2d9c07792622e883a @dmathieu dmathieu 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 e0335e2

Please sign in to comment.