1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #34906 from gregnavis/add-endless-ranges-to-activerecord

Support endless ranges in where
This commit is contained in:
Aaron Patterson 2019-01-11 11:20:05 -08:00 committed by GitHub
commit 3a1b2a2196
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View file

@ -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*

View file

@ -36,14 +36,14 @@ module Arel # :nodoc: all
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))

View file

@ -639,6 +639,18 @@ module Arel
)
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))