aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test
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/test
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/test')
-rw-r--r--activemodel/test/cases/errors_test.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb
index da142ea2c0..27631005e5 100644
--- a/activemodel/test/cases/errors_test.rb
+++ b/activemodel/test/cases/errors_test.rb
@@ -377,6 +377,12 @@ class ErrorsTest < ActiveModel::TestCase
assert_empty errors.details[:name]
end
+ test "delete returns the deleted messages" do
+ errors = ActiveModel::Errors.new(Person.new)
+ errors.add(:name, :invalid)
+ assert_equal errors.delete(:name), ["is invalid"]
+ end
+
test "clear removes details" do
person = Person.new
person.errors.add(:name, :invalid)