thoughtbot--shoulda-matchers/spec/support/unit
Matheus Sales 09bc2609d7
Add `in: range` matcher to validate_numericality_of (#1512)
Closes: #1493

In Rails 7 was added a new option to validate numericality. You can use
`in: range` to specify a range to validate an attribute.

```ruby
class User < ApplicationRecord
  validates :age, numericality: { greater_than_or_equal_to: 18, less_than_or_equal_to: 65 }
end

class User < ApplicationRecord
  validates :age, numericality: { in: 18..65 }
end
```

In this commit we are adding the support matcher to this new
functionality, while also making a refactor on the numericality
matchers that use the concept of submatchers.

We've created a new class (`NumericalityMatchers::Submatcher`) that's
been used by `NumericalityMatchers::RangeMatcher` and
`NumericalityMatchers::ComparisonMatcher`, this new class wil handle
shared logic regarding having submatchers that will check if the parent
matcher is valid or not.

Our new class `Numericality::Matchers::RangeMatcher` is using as
submatchers two `NumericalityMatchers::ComparisonMatcher` instances to
avoid creating new logic to handle this new option and also to replicate
what was being used before this option existed in Rails (see example
above)

In this commit we are adding:

* NumericalityMatchers::RangeMatcher file to support the new `in: range`
  option.
* Specs on ValidateNumericalityOfMatcherSpec file for the new supported
  option, only running on rails_versions > 7.
* NumericalityMatchers::Submatchers file to handle having submatchers
  inside a matcher file.
* Refactors to NumericalityMatchers::ComparisonMatcher.
2022-10-29 08:17:09 -03:00
..
active_record Add Ruby 3.0 support (#1427) 2021-04-09 22:56:49 -03:00
create_model_arguments fix(rubocop): Fix Style, Layout, Lint and other offenses [ci skip] 2020-11-03 10:05:25 -07:00
helpers Add `in: range` matcher to validate_numericality_of (#1512) 2022-10-29 08:17:09 -03:00
matchers Remove ruby 2.5 support (#1415) 2021-03-04 20:42:47 -03:00
model_creation_strategies Update Ruby to the latest version (#1509) 2022-09-25 11:47:21 -03:00
model_creators fix(rubocop): Add trailing comma in args, Hash and Arrays [ci skip] 2020-11-03 10:05:25 -07:00
shared_examples fix(rubocop): Add trailing comma in args, Hash and Arrays [ci skip] 2020-11-03 10:05:25 -07:00
attribute.rb fix(rubocop): Fix Style, Layout, Lint and other offenses [ci skip] 2020-11-03 10:05:25 -07:00
capture.rb Remove Rails 4.2 support (#1422) 2021-03-04 19:43:38 -03:00
change_value.rb fix(rubocop): Fix Layout/LineLength 2020-11-03 10:05:25 -07:00
i18n.rb Reorganize unit tests, part I 2014-11-04 14:43:59 -07:00
load_environment.rb Speed up running unit tests with Zeus 2015-12-13 20:22:21 -07:00
model_creators.rb Extract classes for defining models in tests 2016-01-05 00:58:16 -07:00
rails_application.rb Install ActiveStorage migrations (#1458) 2022-09-26 07:22:03 -03:00
record_builder_with_i18n_validation_message.rb fix(rubocop): Fix Style, Layout, Lint and other offenses [ci skip] 2020-11-03 10:05:25 -07:00
record_validating_confirmation_builder.rb fix(rubocop): Add trailing comma in args, Hash and Arrays [ci skip] 2020-11-03 10:05:25 -07:00
record_with_different_error_attribute_builder.rb fix(rubocop): Fix Style, Layout, Lint and other offenses [ci skip] 2020-11-03 10:05:25 -07:00
validation_matcher_scenario.rb Get rid of some warnings from Ruby 2017-09-17 17:01:50 -05:00