aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorDamien Mathieu <42@dmathieu.com>2011-09-06 18:35:12 +0200
committerDamien Mathieu <42@dmathieu.com>2011-09-06 18:36:18 +0200
commite0335e2ccbdbbd14715877c2d9c07792622e883a (patch)
tree94eccbe0b1bd827d3cd6967fa91508249e353145 /activemodel
parentef14a0ec8647010eed3a8006409739e6d42791a9 (diff)
downloadrails-e0335e2ccbdbbd14715877c2d9c07792622e883a.tar.gz
rails-e0335e2ccbdbbd14715877c2d9c07792622e883a.tar.bz2
rails-e0335e2ccbdbbd14715877c2d9c07792622e883a.zip
add has_key? to ActiveModel::Errors
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/errors.rb1
-rw-r--r--activemodel/test/cases/errors_test.rb6
2 files changed, 7 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 843c0c3cb5..7828434927 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -88,6 +88,7 @@ module ActiveModel
def include?(error)
(v = messages[error]) && v.any?
end
+ alias :has_key? :include?
# Get messages for +key+
def get(key)
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb
index 85ca8ca835..da109a8738 100644
--- a/activemodel/test/cases/errors_test.rb
+++ b/activemodel/test/cases/errors_test.rb
@@ -33,6 +33,12 @@ class ErrorsTest < ActiveModel::TestCase
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]