diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-09-06 09:41:06 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-09-06 09:41:06 -0700 |
commit | 51652a4773ab19c866ea1781b39f46f17faa68f3 (patch) | |
tree | 94eccbe0b1bd827d3cd6967fa91508249e353145 | |
parent | ef14a0ec8647010eed3a8006409739e6d42791a9 (diff) | |
parent | e0335e2ccbdbbd14715877c2d9c07792622e883a (diff) | |
download | rails-51652a4773ab19c866ea1781b39f46f17faa68f3.tar.gz rails-51652a4773ab19c866ea1781b39f46f17faa68f3.tar.bz2 rails-51652a4773ab19c866ea1781b39f46f17faa68f3.zip |
Merge pull request #2893 from dmathieu/errors_has_key
add has_key? to ActiveModel::Errors
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 1 | ||||
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 6 |
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] |