aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/errors.rb
diff options
context:
space:
mode:
authorRadan Skoric <radan.skoric@gmail.com>2015-03-22 23:10:28 +0100
committerRadan Skoric <radan.skoric@gmail.com>2015-03-22 23:18:22 +0100
commit26b35a4096e4725098b447c57f7b663a15caa8b9 (patch)
tree47ee7a11615a67ce119fdf3e5161c0b4260b2ad0 /activemodel/lib/active_model/errors.rb
parentb7b70c8deb48e412bb98859db5cffdc4468e1d68 (diff)
downloadrails-26b35a4096e4725098b447c57f7b663a15caa8b9.tar.gz
rails-26b35a4096e4725098b447c57f7b663a15caa8b9.tar.bz2
rails-26b35a4096e4725098b447c57f7b663a15caa8b9.zip
Fix ActiveModel::Errors#delete return value to stay backward compatible
Rails 5.0 changes to ActiveModel::Errors include addition of `details` that also accidentally changed the return value of `delete`. Since there was no test for that behavior it went unnoticed. This commit adds a test and fixes the regression. Small improvements to comments have also been made. Since `get` is getting deprecated it is better to use `[]` in other methods' code examples. Also, in the module usage example, `def Person.method` was replaced with a more commonly used `def self.method` code style.
Diffstat (limited to 'activemodel/lib/active_model/errors.rb')
-rw-r--r--activemodel/lib/active_model/errors.rb14
1 files changed, 7 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index cbca76d949..e35ed03e74 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -34,11 +34,11 @@ module ActiveModel
# send(attr)
# end
#
- # def Person.human_attribute_name(attr, options = {})
+ # def self.human_attribute_name(attr, options = {})
# attr
# end
#
- # def Person.lookup_ancestors
+ # def self.lookup_ancestors
# [self]
# end
# end
@@ -124,9 +124,9 @@ module ActiveModel
# Set messages for +key+ to +value+.
#
- # person.errors.get(:name) # => ["cannot be nil"]
+ # person.errors[:name] # => ["cannot be nil"]
# person.errors.set(:name, ["can't be nil"])
- # person.errors.get(:name) # => ["can't be nil"]
+ # person.errors[:name] # => ["can't be nil"]
def set(key, value)
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
ActiveModel::Errors#set is deprecated and will be removed in Rails 5.1.
@@ -139,12 +139,12 @@ module ActiveModel
# Delete messages for +key+. Returns the deleted messages.
#
- # person.errors.get(:name) # => ["cannot be nil"]
+ # person.errors[:name] # => ["cannot be nil"]
# person.errors.delete(:name) # => ["cannot be nil"]
- # person.errors.get(:name) # => []
+ # person.errors[:name] # => []
def delete(key)
- messages.delete(key)
details.delete(key)
+ messages.delete(key)
end
# When passed a symbol or a name of a method, returns an array of errors