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

Support endless ranges in where #34906

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Add support for endless ranges introduces in Ruby 2.6.

*Greg Navis*

* Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.

*Ryuta Kamizono*
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/arel/predications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def eq_all(others)

def between(other)
if infinity?(other.begin)
if infinity?(other.end)
if other.end.nil? || infinity?(other.end)
not_in([])
elsif other.exclude_end?
lt(other.end)
else
lteq(other.end)
end
elsif infinity?(other.end)
elsif other.end.nil? || infinity?(other.end)
gteq(other.begin)
elsif other.exclude_end?
gteq(other.begin).and(lt(other.end))
Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/arel/attributes/attribute_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,18 @@ class AttributeTest < Arel::Spec
)
end

if Gem::Version.new("2.6.0") <= Gem::Version.new(RUBY_VERSION)
it "can be constructed with a range implicitly ending at Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(eval("0..")) # Use eval for compatibility with Ruby < 2.6 parser

node.must_equal Nodes::GreaterThanOrEqual.new(
attribute,
Nodes::Casted.new(0, attribute)
)
end
end

it "can be constructed with a quoted range ending at Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(quoted_range(0, ::Float::INFINITY, false))
Expand Down