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

Merge pull request #33361 from jhubert/bugfix/fix-added-string-attributes

Fix regression in use of string attribute in the added? method
This commit is contained in:
Eileen M. Uchitelle 2018-07-14 14:21:37 -04:00 committed by GitHub
commit 05bef14051
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

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

View file

@ -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" }