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:
parent
39310f7930
commit
f48d32c0cf
2 changed files with 11 additions and 0 deletions
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue