From 6c8cf21584ced73ade45529d11463c74b5a0c58f Mon Sep 17 00:00:00 2001 From: Garry Shutler Date: Tue, 14 Oct 2014 09:53:26 +0100 Subject: Add #key? to ActiveModel::Errors Mirror Ruby's Hash#key? --- activemodel/lib/active_model/errors.rb | 2 ++ activemodel/test/cases/errors_test.rb | 11 +++++++++++ 2 files changed, 13 insertions(+) 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! -- cgit v1.2.3