thoughtbot--shoulda-matchers/spec/unit/shoulda/matchers
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
..
action_controller Remove use_before_filter, use_after_filter and use_around_filter matchers (#1431) 2021-03-21 01:10:32 -03:00
active_model Add `in: range` matcher to validate_numericality_of (#1512) 2022-10-29 08:17:09 -03:00
active_record Install ActiveStorage migrations (#1458) 2022-09-26 07:22:03 -03:00
doublespeak fix(rubocop): Fix Style, Layout, Lint and other offenses [ci skip] 2020-11-03 10:05:25 -07:00
independent fix(rubocop): Fix Layout/LineLength 2020-11-03 10:05:25 -07:00
routing fix(rubocop): Add trailing comma in args, Hash and Arrays [ci skip] 2020-11-03 10:05:25 -07:00
util fix(rubocop): Fix Layout/LineLength 2020-11-03 10:05:25 -07:00
doublespeak_spec.rb Make Doublespeak specs runnable without Rails 2015-02-28 23:41:28 -07:00