未验证 提交 05bef140 编写于 作者: E Eileen M. Uchitelle 提交者: GitHub

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

Fix regression in use of string attribute in the added? method
......@@ -328,7 +328,7 @@ def add(attribute, message = :invalid, options = {})
# 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 @@ def test_no_key
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" }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册