From cf03bd45e39def057a2f63e42a3391b7d750dece Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Fri, 26 Dec 2014 15:45:34 -0700 Subject: Allow for handling quoted values in ranges Since Active Record needs to eagerly cast values, we need to check for quoted infinity in our range handling --- lib/arel/predications.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'lib/arel/predications.rb') diff --git a/lib/arel/predications.rb b/lib/arel/predications.rb index ec779dd40f..b05fc6f99a 100644 --- a/lib/arel/predications.rb +++ b/lib/arel/predications.rb @@ -25,15 +25,15 @@ module Arel end def between other - if other.begin == -Float::INFINITY - if other.end == Float::INFINITY + if equals_quoted?(other.begin, -Float::INFINITY) + if equals_quoted?(other.end, Float::INFINITY) not_in([]) elsif other.exclude_end? lt(other.end) else lteq(other.end) end - elsif other.end == Float::INFINITY + elsif equals_quoted?(other.end, Float::INFINITY) gteq(other.begin) elsif other.exclude_end? gteq(other.begin).and(lt(other.end)) @@ -71,15 +71,15 @@ Passing a range to `#in` is deprecated. Call `#between`, instead. end def not_between other - if other.begin == -Float::INFINITY # The range begins with negative infinity - if other.end == Float::INFINITY + if equals_quoted?(other.begin, -Float::INFINITY) + if equals_quoted?(other.end, Float::INFINITY) self.in([]) elsif other.exclude_end? gteq(other.end) else gt(other.end) end - elsif other.end == Float::INFINITY + elsif equals_quoted?(other.end, Float::INFINITY) lt(other.begin) else left = lt(other.begin) @@ -211,5 +211,13 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead. def quoted_array(others) others.map { |v| quoted_node(v) } end + + def equals_quoted?(maybe_quoted, value) + if maybe_quoted.is_a?(Nodes::Quoted) + maybe_quoted.val == value + else + maybe_quoted == value + end + end end end -- cgit v1.2.3