1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

implementing include? on AM::Errors

This commit is contained in:
Aaron Patterson 2011-02-09 09:19:15 -08:00
parent 39310f7930
commit f48d32c0cf
2 changed files with 11 additions and 0 deletions

View file

@ -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]

View file

@ -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]