提交 1c3a6e8f 编写于 作者: R Ryuta Kamizono 提交者: Eugene Kenny

Merge pull request #36696 from inopinatus/support_beginless_ranges

Support beginless ranges in hash conditions.
上级 4e3fd929
* Add support for beginless ranges, introduced in Ruby 2.7.
*Josh Goodall*
* Fix insert_all with enum values
Fixes #38716.
......
......@@ -37,7 +37,7 @@ def eq_all(others)
def between(other)
if unboundable?(other.begin) == 1 || unboundable?(other.end) == -1
self.in([])
elsif open_ended?(other.begin)
elsif other.begin.nil? || open_ended?(other.begin)
if other.end.nil? || open_ended?(other.end)
not_in([])
elsif other.exclude_end?
......@@ -85,7 +85,7 @@ def in_all(others)
def not_between(other)
if unboundable?(other.begin) == 1 || unboundable?(other.end) == -1
not_in([])
elsif open_ended?(other.begin)
elsif other.begin.nil? || open_ended?(other.begin)
if other.end.nil? || open_ended?(other.end)
self.in([])
elsif other.exclude_end?
......
......@@ -638,6 +638,18 @@ class AttributeTest < Arel::Spec
)
end
if Gem::Version.new("2.7.0") <= Gem::Version.new(RUBY_VERSION)
it "can be constructed with a range implicitly starting at Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(eval("..0")) # eval for backwards compatibility
node.must_equal Nodes::LessThanOrEqual.new(
attribute,
Nodes::Casted.new(0, attribute)
)
end
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
......@@ -839,6 +851,18 @@ class AttributeTest < Arel::Spec
)
end
if Gem::Version.new("2.7.0") <= Gem::Version.new(RUBY_VERSION)
it "can be constructed with a range implicitly starting at Infinity" do
attribute = Attribute.new nil, nil
node = attribute.not_between(eval("..0")) # eval for backwards compatibility
node.must_equal Nodes::GreaterThan.new(
attribute,
Nodes::Casted.new(0, attribute)
)
end
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册