thoughtbot--shoulda-matchers/lib/shoulda/matchers/active_model
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
..
allow_value_matcher fix(rubocop): Add trailing comma in args, Hash and Arrays [ci skip] 2020-11-03 10:05:25 -07:00
numericality_matchers Add `in: range` matcher to validate_numericality_of (#1512) 2022-10-29 08:17:09 -03:00
qualifiers feat: implement allow_blank 2022-08-05 11:02:19 -06:00
validation_matcher fix(rubocop): Fix Layout/LineLength 2020-11-03 10:05:25 -07:00
allow_value_matcher.rb fix(rubocop): Fix Layout/LineLength 2020-11-03 10:05:25 -07:00
disallow_value_matcher.rb fix(rubocop): Fix Layout related offenses [ci skip] 2020-11-03 10:05:25 -07:00
errors.rb Extract examples in README to inline documentation 2014-06-20 16:41:27 -06:00
have_secure_password_matcher.rb fix(rubocop): Fix Layout/LineLength 2020-11-03 10:05:25 -07:00
helpers.rb renew deprecated methods (#1444) 2021-06-12 15:41:26 -03:00
numericality_matchers.rb Revert "Use autoloading instead of requiring all files up front" 2020-08-26 10:52:54 -06:00
qualifiers.rb feat: implement allow_blank 2022-08-05 11:02:19 -06:00
validate_absence_of_matcher.rb Fix typo: arbitary -> arbitrary (#1515) 2022-10-18 18:29:02 -03:00
validate_acceptance_of_matcher.rb Fix negative versions of validation matchers 2018-09-15 13:43:30 -03:00
validate_confirmation_of_matcher.rb fix(rubocop): Add trailing comma in args, Hash and Arrays [ci skip] 2020-11-03 10:05:25 -07:00
validate_exclusion_of_matcher.rb fix(rubocop): Fix Layout/LineLength 2020-11-03 10:05:25 -07:00
validate_inclusion_of_matcher.rb Fix the undefined method error for non rails project due to use of many? method. (#1459) 2021-08-31 20:04:37 -03:00
validate_length_of_matcher.rb Fix documentation (#1471) 2021-12-28 14:31:44 -03:00
validate_numericality_of_matcher.rb Add `in: range` matcher to validate_numericality_of (#1512) 2022-10-29 08:17:09 -03:00
validate_presence_of_matcher.rb Add Rails 7 (#1506) 2022-09-15 18:05:15 -03:00
validation_matcher.rb fix(rubocop): Fix Layout/LineLength 2020-11-03 10:05:25 -07:00
validation_message_finder.rb fix(rubocop): Fix Style, Layout, Lint and other offenses [ci skip] 2020-11-03 10:05:25 -07:00
validator.rb Add Appraisal for Rails 6.1 (#1418) 2021-06-03 17:41:27 -03:00