Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: cannot get the first element of beginless range #1614

Closed
pjpires opened this issue Feb 20, 2024 · 0 comments · Fixed by #1615
Closed

RangeError: cannot get the first element of beginless range #1614

pjpires opened this issue Feb 20, 2024 · 0 comments · Fixed by #1615

Comments

@pjpires
Copy link
Contributor

pjpires commented Feb 20, 2024

Description

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

System configuration

shoulda_matchers version: 6.1.0
rails version: 7.1.3
ruby version: 3.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant