Currently, beginless and endless ranges are not correctly handled by .in_range on top of validates_inclusion_of, even though ActiveRecord properly handles beginless and endless ranges.
Reproduction Steps
Given a sample model:
# app/models/past_post.rb
class PastPost < ApplicationRecord
validates :created_on, inclusion: { in: -> { (..Date.yesterday) } }
end
And the respective spec:
# spec/models/past_post_spec.rb
RSpec.describe PastPost do
# ...
describe 'Validations' do
it { is_expected.to validate_inclusion_of(:created_on).in_range(..Date.yesterday) }
end
end
An error is raised instead of correctly asserting the validation:
Failure/Error: it { is_expected.to validate_inclusion_of(:created_on).in_range(..Date.yesterday) }
RangeError:
cannot get the first element of beginless range
A similar issue is raised for endless ranges:
RangeError:
cannot get the maximum of endless range
Description
Currently, beginless and endless ranges are not correctly handled by
.in_range
on top ofvalidates_inclusion_of
, even though ActiveRecord properly handles beginless and endless ranges.Reproduction Steps
Given a sample model:
And the respective spec:
An error is raised instead of correctly asserting the validation:
A similar issue is raised for endless ranges:
System configuration
shoulda_matchers version: 6.1.0 rails version: 7.1.3 ruby version: 3.2.2