diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-06-23 11:54:48 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-06-23 11:54:48 -0300 |
commit | 71e92992e66f461acaabc3ac2f3ec6480167962e (patch) | |
tree | 6b5c1c8c96f17529d31a98244aa185a279dd57ca /spec/engines/sql/unit | |
parent | f68115023ecc02d21d982661ba806acec095842d (diff) | |
download | rails-71e92992e66f461acaabc3ac2f3ec6480167962e.tar.gz rails-71e92992e66f461acaabc3ac2f3ec6480167962e.tar.bz2 rails-71e92992e66f461acaabc3ac2f3ec6480167962e.zip |
Add support for counting rows with conditions or limit using a subquery.
Diffstat (limited to 'spec/engines/sql/unit')
-rw-r--r-- | spec/engines/sql/unit/relations/take_spec.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/engines/sql/unit/relations/take_spec.rb b/spec/engines/sql/unit/relations/take_spec.rb index cc3c3dbbf5..1e0d3e3cfe 100644 --- a/spec/engines/sql/unit/relations/take_spec.rb +++ b/spec/engines/sql/unit/relations/take_spec.rb @@ -52,6 +52,24 @@ module Arel }) end end + + it "manufactures count sql with limit" do + sql = Take.new(@relation.project(@relation[:id].count), @taken).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT COUNT(`users`.`id`) AS count_id + FROM (SELECT 1 FROM `users` LIMIT 4) + }) + end + + adapter_is_not :mysql, :oracle do + sql.should be_like(%Q{ + SELECT COUNT("users"."id") AS count_id + FROM (SELECT 1 FROM "users" LIMIT 4) + }) + end + end end end end |