diff options
author | bigxiang <bigxiang@gmail.com> | 2014-08-23 21:01:12 +0800 |
---|---|---|
committer | bigxiang <bigxiang@gmail.com> | 2014-08-23 21:01:12 +0800 |
commit | d27bfef96a86e7278dee297a8af3612ebefbe898 (patch) | |
tree | 3933dc67a14bb873b9d292ec1174a5970faafe9a | |
parent | 53bc8426648cc93695525e8f12102cd416b2d772 (diff) | |
download | rails-d27bfef96a86e7278dee297a8af3612ebefbe898.tar.gz rails-d27bfef96a86e7278dee297a8af3612ebefbe898.tar.bz2 rails-d27bfef96a86e7278dee297a8af3612ebefbe898.zip |
Fix lt & lteq don't accept most of values.
-rw-r--r-- | lib/arel/predications.rb | 12 | ||||
-rw-r--r-- | test/attributes/test_attribute.rb | 6 |
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/arel/predications.rb b/lib/arel/predications.rb index 78cd87d430..1941383068 100644 --- a/lib/arel/predications.rb +++ b/lib/arel/predications.rb @@ -31,7 +31,7 @@ module Arel when Range if other.begin == -Float::INFINITY if other.end == Float::INFINITY - Nodes::NotIn.new self, [] + Nodes::NotIn.new self, [] elsif other.exclude_end? Nodes::LessThan.new(self, Nodes.build_quoted(other.end, self)) else @@ -67,20 +67,20 @@ module Arel Arel::Nodes::NotIn.new(self, other.ast) when Range if other.begin == -Float::INFINITY # The range begins with negative infinity - if other.end == Float::INFINITY + if other.end == Float::INFINITY Nodes::In.new self, [] # The range is infinite, so return an empty range elsif other.exclude_end? Nodes::GreaterThanOrEqual.new(self, Nodes.build_quoted(other.end, self)) else Nodes::GreaterThan.new(self, Nodes.build_quoted(other.end, self)) end - elsif other.end == Float::INFINITY + elsif other.end == Float::INFINITY Nodes::LessThan.new(self, Nodes.build_quoted(other.begin, self)) else left = Nodes::LessThan.new(self, Nodes.build_quoted(other.begin, self)) if other.exclude_end? right = Nodes::GreaterThanOrEqual.new(self, Nodes.build_quoted(other.end, self)) - else + else right = Nodes::GreaterThan.new(self, Nodes.build_quoted(other.end, self)) end Nodes::Or.new left, right @@ -149,7 +149,7 @@ module Arel end def lt right - Nodes::LessThan.new self, right + Nodes::LessThan.new self, Nodes.build_quoted(right, self) end def lt_any others @@ -161,7 +161,7 @@ module Arel end def lteq right - Nodes::LessThanOrEqual.new self, right + Nodes::LessThanOrEqual.new self, Nodes.build_quoted(right, self) end def lteq_any others diff --git a/test/attributes/test_attribute.rb b/test/attributes/test_attribute.rb index f55e39cfe9..12dd25291e 100644 --- a/test/attributes/test_attribute.rb +++ b/test/attributes/test_attribute.rb @@ -180,6 +180,9 @@ module Arel mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE "users"."id" < 10 } + + mgr.where relation[:created_at].lt(::Time.now) + mgr.to_sql.must_match %{"users"."created_at" <} end end @@ -228,6 +231,9 @@ module Arel mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE "users"."id" <= 10 } + + mgr.where relation[:created_at].lteq(::Time.now) + mgr.to_sql.must_match %{"users"."created_at" <=} end end |