aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorJeremy Baker <jhubert@gmail.com>2018-07-14 00:57:43 -0500
committerJeremy Baker <jhubert@gmail.com>2018-07-14 13:19:46 -0500
commita19918124d7d7dcaf546294d9357335c43fbc0ac (patch)
tree0f6abf0dacb1decd2e2d917bac8dbd8d449bc481 /activemodel
parentbd5eba1adff8fa72429f5889ae26097e9756ceb0 (diff)
downloadrails-a19918124d7d7dcaf546294d9357335c43fbc0ac.tar.gz
rails-a19918124d7d7dcaf546294d9357335c43fbc0ac.tar.bz2
rails-a19918124d7d7dcaf546294d9357335c43fbc0ac.zip
Ensure attribute is a symbol in the added? method
Diffstat (limited to 'activemodel')
-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" }