From e0335e2ccbdbbd14715877c2d9c07792622e883a Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Tue, 6 Sep 2011 18:35:12 +0200 Subject: [PATCH] add has_key? to ActiveModel::Errors --- activemodel/lib/active_model/errors.rb | 1 + activemodel/test/cases/errors_test.rb | 6 ++++++ 2 files changed, 7 insertions(+) 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]