diff options
author | Bryan Helmkamp <bryan@brynary.com> | 2009-05-16 21:13:32 -0400 |
---|---|---|
committer | Bryan Helmkamp <bryan@brynary.com> | 2009-05-17 13:17:07 -0400 |
commit | 49d119ae84bbb7cd180ca855cf48997dc731554c (patch) | |
tree | 3bae397d3e2b5ee76bd89a87ccbf421d814fec74 /spec/arel/unit/relations/project_spec.rb | |
parent | 4096d192a1e7cdf0115f5a4cf33d102b176cb8cd (diff) | |
download | rails-49d119ae84bbb7cd180ca855cf48997dc731554c.tar.gz rails-49d119ae84bbb7cd180ca855cf48997dc731554c.tar.bz2 rails-49d119ae84bbb7cd180ca855cf48997dc731554c.zip |
Adding spec:mysql and spec:sqlite3 tasks
Diffstat (limited to 'spec/arel/unit/relations/project_spec.rb')
-rw-r--r-- | spec/arel/unit/relations/project_spec.rb | 89 |
1 files changed, 71 insertions, 18 deletions
diff --git a/spec/arel/unit/relations/project_spec.rb b/spec/arel/unit/relations/project_spec.rb index f389b18c54..d2d1fb3873 100644 --- a/spec/arel/unit/relations/project_spec.rb +++ b/spec/arel/unit/relations/project_spec.rb @@ -20,10 +20,21 @@ module Arel describe '#to_sql' do describe 'when given an attribute' do it "manufactures sql with a limited select clause" do - Project.new(@relation, @attribute).to_sql.should be_like(" - SELECT `users`.`id` - FROM `users` - ") + sql = Project.new(@relation, @attribute).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT `users`.`id` + FROM `users` + }) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{ + SELECT "users"."id" + FROM "users" + }) + end end end @@ -33,33 +44,75 @@ module Arel end it "manufactures sql with scalar selects" do - Project.new(@relation, @scalar_relation).to_sql.should be_like(" - SELECT (SELECT `users`.`name` FROM `users`) AS `users` FROM `users` - ") + sql = Project.new(@relation, @scalar_relation).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT (SELECT `users`.`name` FROM `users`) AS `users` FROM `users` + }) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{ + SELECT (SELECT "users"."name" FROM "users") AS "users" FROM "users" + }) + end end end describe 'when given a string' do it "passes the string through to the select clause" do - Project.new(@relation, 'asdf').to_sql.should be_like(" - SELECT asdf FROM `users` - ") + sql = Project.new(@relation, 'asdf').to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT asdf FROM `users` + }) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{ + SELECT asdf FROM "users" + }) + end end end describe 'when given an expression' do it 'manufactures sql with expressions' do - @relation.project(@attribute.count).to_sql.should be_like(" - SELECT COUNT(`users`.`id`) AS count_id - FROM `users` - ") + sql = @relation.project(@attribute.count).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT COUNT(`users`.`id`) AS count_id + FROM `users` + }) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{ + SELECT COUNT("users"."id") AS count_id + FROM "users" + }) + end end it 'manufactures sql with distinct expressions' do - @relation.project(@attribute.count(true)).to_sql.should be_like(" - SELECT COUNT(DISTINCT `users`.`id`) AS count_id - FROM `users` - ") + sql = @relation.project(@attribute.count(true)).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT COUNT(DISTINCT `users`.`id`) AS count_id + FROM `users` + }) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{ + SELECT COUNT(DISTINCT "users"."id") AS count_id + FROM "users" + }) + end end end end |