mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure attribute is a symbol in the added? method
This commit is contained in:
parent
bd5eba1adf
commit
a19918124d
2 changed files with 7 additions and 1 deletions
|
@ -328,7 +328,7 @@ module ActiveModel
|
|||
# person.errors.added? :name, "is too long" # => false
|
||||
def added?(attribute, message = :invalid, options = {})
|
||||
if message.is_a? Symbol
|
||||
self.details[attribute].map { |e| e[:error] }.include? message
|
||||
self.details[attribute.to_sym].map { |e| e[:error] }.include? message
|
||||
else
|
||||
message = message.call if message.respond_to?(:call)
|
||||
message = normalize_message(attribute, message, options)
|
||||
|
|
|
@ -185,6 +185,12 @@ class ErrorsTest < ActiveModel::TestCase
|
|||
assert person.errors.added?(:name, :blank)
|
||||
end
|
||||
|
||||
test "added? returns true when string attribute is used with a symbol message" do
|
||||
person = Person.new
|
||||
person.errors.add(:name, :blank)
|
||||
assert person.errors.added?("name", :blank)
|
||||
end
|
||||
|
||||
test "added? handles proc messages" do
|
||||
person = Person.new
|
||||
message = Proc.new { "cannot be blank" }
|
||||
|
|
Loading…
Reference in a new issue