diff options
author | Alessandro Rodi <alessandro.rodi@renuo.ch> | 2017-11-10 09:38:05 +0100 |
---|---|---|
committer | Alessandro Rodi <alessandro.rodi@renuo.ch> | 2017-11-13 17:27:47 +0100 |
commit | 15cb4efadb61a8813967d3c25f4adfc9a918a0c0 (patch) | |
tree | 7e5a14f9f6675c3ca159772271d784a00be4ea9d /activemodel/lib | |
parent | 8c7967c9b916fe625e7ce10591b101abde3be4f5 (diff) | |
download | rails-15cb4efadb61a8813967d3c25f4adfc9a918a0c0.tar.gz rails-15cb4efadb61a8813967d3c25f4adfc9a918a0c0.tar.bz2 rails-15cb4efadb61a8813967d3c25f4adfc9a918a0c0.zip |
fix bug on added? method
fix rubocop issues
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 971bdd08b1..275e3f1313 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -322,9 +322,13 @@ module ActiveModel # person.errors.added? :name, :too_long # => false # person.errors.added? :name, "is too long" # => false def added?(attribute, message = :invalid, options = {}) - message = message.call if message.respond_to?(:call) - message = normalize_message(attribute, message, options) - self[attribute].include? message + if message.is_a? Symbol + self.details[attribute].map { |e| e[:error] }.include? message + else + message = message.call if message.respond_to?(:call) + message = normalize_message(attribute, message, options) + self[attribute].include? message + end end # Returns all the full error messages in an array. |