aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2018-07-14 14:21:37 -0400
committerGitHub <noreply@github.com>2018-07-14 14:21:37 -0400
commit05bef140519fe3410fd8d352f5ea84fd1a278063 (patch)
tree85b0fe21ae9066030a8b4a82cf9196eb60cef1bf
parenta8d63c2fad0ca968b8685a0c134d9cdc8e5aae6c (diff)
parenta19918124d7d7dcaf546294d9357335c43fbc0ac (diff)
downloadrails-05bef140519fe3410fd8d352f5ea84fd1a278063.tar.gz
rails-05bef140519fe3410fd8d352f5ea84fd1a278063.tar.bz2
rails-05bef140519fe3410fd8d352f5ea84fd1a278063.zip
Merge pull request #33361 from jhubert/bugfix/fix-added-string-attributes
Fix regression in use of string attribute in the added? method
-rw-r--r--activemodel/lib/active_model/errors.rb2
-rw-r--r--activemodel/test/cases/errors_test.rb6
2 files changed, 7 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 56404a036c..edc30ee64d 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -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)
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb
index 6ff3be1308..41ff6443fe 100644
--- a/activemodel/test/cases/errors_test.rb
+++ b/activemodel/test/cases/errors_test.rb
@@ -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" }