aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-10-14 10:28:57 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-10-14 10:28:57 -0300
commit5a5073301c66b7999ad25c18a22d44922002c689 (patch)
tree17e8f85e3189fca07ebbd4278cb8aef8b65dcea0
parente5c46246a2dff0e90950c537f12fb93d7452edaf (diff)
parent6c8cf21584ced73ade45529d11463c74b5a0c58f (diff)
downloadrails-5a5073301c66b7999ad25c18a22d44922002c689.tar.gz
rails-5a5073301c66b7999ad25c18a22d44922002c689.tar.bz2
rails-5a5073301c66b7999ad25c18a22d44922002c689.zip
Merge pull request #17253 from gshutler/activemodel-errors-key
Add #key? to ActiveModel::Errors
-rw-r--r--activemodel/lib/active_model/errors.rb2
-rw-r--r--activemodel/test/cases/errors_test.rb11
2 files changed, 13 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 1b46727351..9105ef5dd6 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -98,6 +98,8 @@ module ActiveModel
end
# aliases include?
alias :has_key? :include?
+ # aliases include?
+ alias :key? :include?
# Get messages for +key+.
#
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb
index 42d0365521..efedd9055f 100644
--- a/activemodel/test/cases/errors_test.rb
+++ b/activemodel/test/cases/errors_test.rb
@@ -59,6 +59,17 @@ class ErrorsTest < ActiveModel::TestCase
assert_equal false, errors.has_key?(:name), 'errors should not have key :name'
end
+ def test_key?
+ errors = ActiveModel::Errors.new(self)
+ errors[:foo] = 'omg'
+ assert_equal true, errors.key?(:foo), 'errors should have key :foo'
+ end
+
+ def test_no_key
+ errors = ActiveModel::Errors.new(self)
+ assert_equal false, errors.key?(:name), 'errors should not have key :name'
+ end
+
test "clear errors" do
person = Person.new
person.validate!