diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-09-12 18:11:36 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-09-12 18:11:36 -0300 |
commit | 1ee24112e8b42879f02fcee995e222dcabb2cb64 (patch) | |
tree | 9de998d2411a5aff7324cfe3b6816b87751b343b | |
parent | f8c0202f46e52761082c6ff4a1f3eedec1d1ddc2 (diff) | |
parent | 3f8ac523cbf2ebc544e5eec0db2b3247f396f9b3 (diff) | |
download | rails-1ee24112e8b42879f02fcee995e222dcabb2cb64.tar.gz rails-1ee24112e8b42879f02fcee995e222dcabb2cb64.tar.bz2 rails-1ee24112e8b42879f02fcee995e222dcabb2cb64.zip |
Merge pull request #304 from bigxiang/fix_lt_and_lteq_error
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 | 44 |
2 files changed, 50 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 dd2d9d343e..b50bb60b1e 100644 --- a/test/attributes/test_attribute.rb +++ b/test/attributes/test_attribute.rb @@ -85,6 +85,17 @@ module Arel SELECT * FROM "users" WHERE "users"."karma" > (SELECT AVG("users"."karma") FROM "users") } end + + it 'should accept various data types.' do + relation = Table.new(:users) + mgr = relation.project relation[:id] + mgr.where relation[:name].gt('fake_name') + mgr.to_sql.must_match %{"users"."name" > 'fake_name'} + + current_time = ::Time.now + mgr.where relation[:created_at].gt(current_time) + mgr.to_sql.must_match %{"users"."created_at" > '#{current_time}'} + end end describe '#gt_any' do @@ -133,6 +144,17 @@ module Arel SELECT "users"."id" FROM "users" WHERE "users"."id" >= 10 } end + + it 'should accept various data types.' do + relation = Table.new(:users) + mgr = relation.project relation[:id] + mgr.where relation[:name].gteq('fake_name') + mgr.to_sql.must_match %{"users"."name" >= 'fake_name'} + + current_time = ::Time.now + mgr.where relation[:created_at].gteq(current_time) + mgr.to_sql.must_match %{"users"."created_at" >= '#{current_time}'} + end end describe '#gteq_any' do @@ -181,6 +203,17 @@ module Arel SELECT "users"."id" FROM "users" WHERE "users"."id" < 10 } end + + it 'should accept various data types.' do + relation = Table.new(:users) + mgr = relation.project relation[:id] + mgr.where relation[:name].lt('fake_name') + mgr.to_sql.must_match %{"users"."name" < 'fake_name'} + + current_time = ::Time.now + mgr.where relation[:created_at].lt(current_time) + mgr.to_sql.must_match %{"users"."created_at" < '#{current_time}'} + end end describe '#lt_any' do @@ -229,6 +262,17 @@ module Arel SELECT "users"."id" FROM "users" WHERE "users"."id" <= 10 } end + + it 'should accept various data types.' do + relation = Table.new(:users) + mgr = relation.project relation[:id] + mgr.where relation[:name].lteq('fake_name') + mgr.to_sql.must_match %{"users"."name" <= 'fake_name'} + + current_time = ::Time.now + mgr.where relation[:created_at].lteq(current_time) + mgr.to_sql.must_match %{"users"."created_at" <= '#{current_time}'} + end end describe '#lteq_any' do |