diff options
author | Edouard CHIN <edouard.chin@shopify.com> | 2019-07-20 21:26:43 +0200 |
---|---|---|
committer | Edouard CHIN <edouard.chin@shopify.com> | 2019-07-20 21:26:43 +0200 |
commit | ab21db050d9cd64628768af3fa4b650550667550 (patch) | |
tree | aa9638b248c7a0f25ce66e1bc6e8058339ba2883 /activemodel/test | |
parent | 400b2103540e1dfb370eab29a891687d778ad357 (diff) | |
download | rails-ab21db050d9cd64628768af3fa4b650550667550.tar.gz rails-ab21db050d9cd64628768af3fa4b650550667550.tar.bz2 rails-ab21db050d9cd64628768af3fa4b650550667550.zip |
Fix deprecation on `AM::Errors` when each is called indirectly:
- `AM::Errors#each` is implemented for the `Enumerator` module and
get called indirectly by a bunch of method in the ruby land
(map, first, select ...)
These methods have a `-1` arity as they are written in C and they
wrongly trigger a deprecation warning.
This commit fixes that and correctectly return a `AM::Error` object
when `each` is called with a negative arity.
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index d66d6ceff0..60b20ab59f 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -44,6 +44,14 @@ class ErrorsTest < ActiveModel::TestCase assert_includes errors, "foo", "errors should include 'foo' as :foo" end + def test_each_when_arity_is_negative + errors = ActiveModel::Errors.new(Person.new) + errors.add(:name, :blank) + errors.add(:gender, :blank) + + assert_equal([:name, :gender], errors.map(&:attribute)) + end + def test_any? errors = ActiveModel::Errors.new(Person.new) errors.add(:name) |