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

Properly handle impossible cases in (not_)between

Fixes #43521
This commit is contained in:
Fabian Schwahn 2021-10-26 05:55:03 +00:00 committed by GitHub
parent 31ad3f1529
commit 92604518d1
2 changed files with 38 additions and 2 deletions

View file

@ -39,7 +39,11 @@ module Arel # :nodoc: all
self.in([])
elsif open_ended?(other.begin)
if open_ended?(other.end)
not_in([])
if infinity?(other.begin) == 1 || infinity?(other.end) == -1
self.in([])
else
not_in([])
end
elsif other.exclude_end?
lt(other.end)
else
@ -80,7 +84,11 @@ module Arel # :nodoc: all
not_in([])
elsif open_ended?(other.begin)
if open_ended?(other.end)
self.in([])
if infinity?(other.begin) == 1 || infinity?(other.end) == -1
not_in([])
else
self.in([])
end
elsif other.exclude_end?
gteq(other.end)
else

View file

@ -668,6 +668,20 @@ module Arel
)
end
it "can be constructed with an endless range starting from Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(::Float::INFINITY..)
_(node).must_equal Nodes::In.new(attribute, [])
end
it "can be constructed with a beginless range ending in -Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(..-::Float::INFINITY)
_(node).must_equal Nodes::In.new(attribute, [])
end
it "can be constructed with an exclusive range" do
attribute = Attribute.new nil, nil
node = attribute.between(0...3)
@ -877,6 +891,20 @@ module Arel
)
end
it "can be constructed with an endless range starting from Infinity" do
attribute = Attribute.new nil, nil
node = attribute.not_between(::Float::INFINITY..)
_(node).must_equal Nodes::NotIn.new(attribute, [])
end
it "can be constructed with a beginless range ending in -Infinity" do
attribute = Attribute.new nil, nil
node = attribute.not_between(..-::Float::INFINITY)
_(node).must_equal Nodes::NotIn.new(attribute, [])
end
it "can be constructed with an exclusive range" do
attribute = Attribute.new nil, nil
node = attribute.not_between(0...3)