mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
add has_key? to ActiveModel::Errors
This commit is contained in:
parent
ef14a0ec86
commit
e0335e2ccb
2 changed files with 7 additions and 0 deletions
|
@ -88,6 +88,7 @@ module ActiveModel
|
||||||
def include?(error)
|
def include?(error)
|
||||||
(v = messages[error]) && v.any?
|
(v = messages[error]) && v.any?
|
||||||
end
|
end
|
||||||
|
alias :has_key? :include?
|
||||||
|
|
||||||
# Get messages for +key+
|
# Get messages for +key+
|
||||||
def get(key)
|
def get(key)
|
||||||
|
|
|
@ -33,6 +33,12 @@ class ErrorsTest < ActiveModel::TestCase
|
||||||
assert errors.include?(:foo), 'errors should include :foo'
|
assert errors.include?(:foo), 'errors should include :foo'
|
||||||
end
|
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
|
test "should return true if no errors" do
|
||||||
person = Person.new
|
person = Person.new
|
||||||
person.errors[:foo]
|
person.errors[:foo]
|
||||||
|
|
Loading…
Reference in a new issue