diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2019-04-30 16:54:40 -0500 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2019-04-30 16:54:40 -0500 |
commit | 2ada222f1edbc827a1c06bdb3110d7a0ee808a24 (patch) | |
tree | e31a7a095cc262c3534565eb2e6bad5d5e703e7d /activemodel | |
parent | 681b0c1f2a2a51becad928ff157d59082ce5c1bd (diff) | |
download | rails-2ada222f1edbc827a1c06bdb3110d7a0ee808a24.tar.gz rails-2ada222f1edbc827a1c06bdb3110d7a0ee808a24.tar.bz2 rails-2ada222f1edbc827a1c06bdb3110d7a0ee808a24.zip |
any? should be delegated to the errors list
Otherwise we get deprecation warnings in the generated scaffold template files
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 2 | ||||
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index fd87d3c9bc..d7bcfacce3 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -64,7 +64,7 @@ module ActiveModel include Enumerable extend Forwardable - def_delegators :@errors, :size, :clear, :blank?, :empty?, :uniq! + def_delegators :@errors, :size, :clear, :blank?, :empty?, :uniq!, :any? # TODO: forward all enumerable methods after `each` deprecation is removed. def_delegators :@errors, :count diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 0837e9db96..baaf404f2e 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -44,6 +44,17 @@ class ErrorsTest < ActiveModel::TestCase assert_includes errors, "foo", "errors should include 'foo' as :foo" end + def test_any? + errors = ActiveModel::Errors.new(Person.new) + errors.add(:name) + assert_not_deprecated { + assert errors.any?, "any? should return true" + } + assert_not_deprecated { + assert errors.any? { |_| true }, "any? should return true" + } + end + def test_dup errors = ActiveModel::Errors.new(Person.new) errors.add(:name) |