diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-07-17 17:35:16 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-17 17:35:16 +0900 |
commit | 2a28b7c292b3d6c0a01722f50beedb8ec1bf074c (patch) | |
tree | 19eac18ee91b8ac284163b79df74af5d25c7d22b /activerecord | |
parent | 32e5f9049c3ef626c9ba7b643c06b09b1ca8f6c1 (diff) | |
parent | b19150448bcf65362c34b5a741ce162cd2b79216 (diff) | |
download | rails-2a28b7c292b3d6c0a01722f50beedb8ec1bf074c.tar.gz rails-2a28b7c292b3d6c0a01722f50beedb8ec1bf074c.tar.bz2 rails-2a28b7c292b3d6c0a01722f50beedb8ec1bf074c.zip |
Merge pull request #36696 from inopinatus/support_beginless_ranges
Support beginless ranges in hash conditions.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activerecord/lib/arel/predications.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/arel/attributes/attribute_test.rb | 24 |
3 files changed, 30 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 184e881b25..b39f423700 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Add support for beginless ranges, introduced in Ruby 2.7. + + *Josh Goodall* + * Add database_exists? method to connection adapters to check if a database exists. *Guilherme Mansur* diff --git a/activerecord/lib/arel/predications.rb b/activerecord/lib/arel/predications.rb index dece478615..895d394363 100644 --- a/activerecord/lib/arel/predications.rb +++ b/activerecord/lib/arel/predications.rb @@ -37,7 +37,7 @@ module Arel # :nodoc: all 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 @@ Passing a range to `#in` is deprecated. Call `#between`, instead. 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? diff --git a/activerecord/test/cases/arel/attributes/attribute_test.rb b/activerecord/test/cases/arel/attributes/attribute_test.rb index c7bd0a053b..7ebb90c6fd 100644 --- a/activerecord/test/cases/arel/attributes/attribute_test.rb +++ b/activerecord/test/cases/arel/attributes/attribute_test.rb @@ -638,6 +638,18 @@ module Arel ) 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 @@ module Arel ) 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 |