diff options
-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) |