thoughtbot--shoulda-matchers/spec/support/unit/helpers
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_pack_versions.rb Remove unnecessary conditions for rails 5.0 (#1426) 2021-03-23 14:06:23 -03:00
active_model_helpers.rb Handle RangeErrors emitted now in ActiveRecord 4.2 2015-01-22 21:05:09 -07:00
active_model_versions.rb Support custom has_secure_password attributes 2020-09-14 11:37:19 -06:00
active_record_versions.rb Remove rails 5.1 support (#1429) 2021-04-17 17:13:09 -03:00
active_resource_builder.rb Don't require ActiveResource tests under Rails 5 2017-09-17 17:01:50 -05:00
allow_value_matcher_helpers.rb Reorganize unit tests, part II 2014-11-05 09:53:20 -07:00
application_configuration_helpers.rb Clear up confusion w/ presence around belongs_to associations 2019-06-01 17:43:13 -06:00
class_builder.rb Add Rails 7 (#1506) 2022-09-15 18:05:15 -03:00
column_type_helpers.rb Add support for Postgres 2015-02-12 16:01:00 -07:00
confirmation_matcher_helpers.rb fix(rubocop): Fix Layout/LineLength 2020-11-03 10:05:25 -07:00
controller_builder.rb fix(rubocop): Fix Layout related offenses [ci skip] 2020-11-03 10:05:25 -07:00
database_helpers.rb Fix tests for array columns 2019-07-14 18:28:19 -06:00
i18n_faker.rb Add failing tests for issue 1146 2019-01-29 23:33:06 -07:00
mailer_builder.rb fix(rubocop): Fix Style, Layout, Lint and other offenses [ci skip] 2020-11-03 10:05:25 -07:00
message_helpers.rb fix(rubocop): Satisfy Style/StringLiterals with single_quotes [ci skip] 2020-11-03 10:05:25 -07:00
model_builder.rb Add Ruby 3.0 support (#1427) 2021-04-09 22:56:49 -03:00
rails_versions.rb Add `in: range` matcher to validate_numericality_of (#1512) 2022-10-29 08:17:09 -03:00
validation_matcher_scenario_helpers.rb fix(rubocop): Add trailing comma in args, Hash and Arrays [ci skip] 2020-11-03 10:05:25 -07:00