From f48d32c0cff36cb505443ff72738def3a82c2886 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 9 Feb 2011 09:19:15 -0800 Subject: [PATCH] implementing include? on AM::Errors --- activemodel/lib/active_model/errors.rb | 5 +++++ activemodel/test/cases/errors_test.rb | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 003c94a409..5e3cf510b0 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -84,6 +84,11 @@ module ActiveModel messages.clear end + # Do the error messages include an error with key +error+? + def include?(error) + messages.include? error + end + # Get messages for +key+ def get(key) messages[key] diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 8cb8f7ba44..a24cac40ad 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -27,6 +27,12 @@ class ErrorsTest < ActiveModel::TestCase end end + def test_include? + errors = ActiveModel::Errors.new(self) + errors[:foo] = 'omg' + assert errors.include?(:foo), 'errors should include :foo' + end + test "should return true if no errors" do person = Person.new person.errors[:foo]