diff options
author | bigxiang <bigxiang@gmail.com> | 2014-08-31 22:11:25 +0800 |
---|---|---|
committer | bigxiang <bigxiang@gmail.com> | 2014-08-31 22:11:25 +0800 |
commit | 3f8ac523cbf2ebc544e5eec0db2b3247f396f9b3 (patch) | |
tree | 5bb7abfe5ee3ca3e20ed6dd5a7982b0c7ccff025 /test | |
parent | d27bfef96a86e7278dee297a8af3612ebefbe898 (diff) | |
download | rails-3f8ac523cbf2ebc544e5eec0db2b3247f396f9b3.tar.gz rails-3f8ac523cbf2ebc544e5eec0db2b3247f396f9b3.tar.bz2 rails-3f8ac523cbf2ebc544e5eec0db2b3247f396f9b3.zip |
Change specs to cover lt, lteq, gt and gteq.
Diffstat (limited to 'test')
-rw-r--r-- | test/attributes/test_attribute.rb | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/test/attributes/test_attribute.rb b/test/attributes/test_attribute.rb index 12dd25291e..50da1cea5b 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") AS avg_id 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 @@ -180,9 +202,17 @@ module Arel mgr.to_sql.must_be_like %{ 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'} - mgr.where relation[:created_at].lt(::Time.now) - mgr.to_sql.must_match %{"users"."created_at" <} + current_time = ::Time.now + mgr.where relation[:created_at].lt(current_time) + mgr.to_sql.must_match %{"users"."created_at" < '#{current_time}'} end end @@ -231,9 +261,17 @@ module Arel mgr.to_sql.must_be_like %{ 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'} - mgr.where relation[:created_at].lteq(::Time.now) - mgr.to_sql.must_match %{"users"."created_at" <=} + current_time = ::Time.now + mgr.where relation[:created_at].lteq(current_time) + mgr.to_sql.must_match %{"users"."created_at" <= '#{current_time}'} end end |