rails--rails/activemodel/test/cases/validations
Ricardo Díaz 93cbc30f34 Use Enumerator#all? and Enumerator#any? with classes instead of iterations
These methods have changed in Ruby 2.5 to be more akin to grep:

https://bugs.ruby-lang.org/issues/11286

Using classes seems to be faster (and a bit more expressive) than iterating over
the collection items:

```
Warming up --------------------------------------
    #all? with class   504.000  i/100ms
     #all? with proc   189.000  i/100ms
Calculating -------------------------------------
    #all? with class      4.960k (± 1.6%) i/s -     25.200k in   5.082049s
     #all? with proc      1.874k (± 2.8%) i/s -      9.450k in   5.047866s

Comparison:
    #all? with class:     4959.9 i/s
     #all? with proc:     1873.8 i/s - 2.65x  (± 0.00) slower
```

Benchmark script:

```ruby
require "minitest/autorun"
require "benchmark/ips"

class BugTest < Minitest::Test
  def test_enumerators_with_classes
    arr = (1..10000).to_a << nil

    assert_equal arr.all?(Integer), arr.all? { |v| v.is_a?(Integer) }

    Benchmark.ips do |x|
      x.report("#all? with class") do
        arr.all?(Integer)
      end

      x.report("#all? with proc") do
        arr.all? { |v| v.is_a?(Integer) }
      end

      x.compare!
    end
  end
end
```
2021-02-07 01:29:50 -05:00
..
absence_validation_test.rb Revert "No such class since 8d2866bb80fbe81acb04f5b0c44f152f571fb29f" 2019-08-02 00:25:13 -04:00
acceptance_validation_test.rb Fix multi-threaded issue for `AcceptanceValidator` 2019-11-03 12:55:30 +09:00
callbacks_test.rb Make sure the :if options of callbacks is not mutated 2020-12-29 03:56:54 +00:00
conditional_validation_test.rb Revert "No such class since 8d2866bb80fbe81acb04f5b0c44f152f571fb29f" 2019-08-02 00:25:13 -04:00
confirmation_validation_test.rb Revert "No such class since 8d2866bb80fbe81acb04f5b0c44f152f571fb29f" 2019-08-02 00:25:13 -04:00
exclusion_validation_test.rb Revert "No such class since 8d2866bb80fbe81acb04f5b0c44f152f571fb29f" 2019-08-02 00:25:13 -04:00
format_validation_test.rb Revert "No such class since 8d2866bb80fbe81acb04f5b0c44f152f571fb29f" 2019-08-02 00:25:13 -04:00
i18n_generate_message_validation_test.rb Revert "No such class since 8d2866bb80fbe81acb04f5b0c44f152f571fb29f" 2019-08-02 00:25:13 -04:00
i18n_validation_test.rb Pass in base to Error.human_attribute_names 2020-10-22 16:50:00 -03:00
inclusion_validation_test.rb Merge pull request #22610 from KevinSjoberg/feature/array-member-inclusion 2020-08-03 00:09:35 +09:30
length_validation_test.rb Add missing test for LengthValidation giving the value via Symbol 2020-10-02 13:37:08 +09:00
numericality_validation_test.rb Add validate numericality in range 2021-01-05 22:56:58 +01:00
presence_validation_test.rb Revert "No such class since 8d2866bb80fbe81acb04f5b0c44f152f571fb29f" 2019-08-02 00:25:13 -04:00
validates_test.rb Always load validator class to verify it exists 2019-08-26 11:52:34 +01:00
validations_context_test.rb Revert "No such class since 8d2866bb80fbe81acb04f5b0c44f152f571fb29f" 2019-08-02 00:25:13 -04:00
with_validation_test.rb Use Enumerator#all? and Enumerator#any? with classes instead of iterations 2021-02-07 01:29:50 -05:00