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/predicates/in_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/predicates/in_spec.rb')
-rw-r--r-- | spec/arel/unit/predicates/in_spec.rb | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/spec/arel/unit/predicates/in_spec.rb b/spec/arel/unit/predicates/in_spec.rb index 797798a77f..9107da9d4b 100644 --- a/spec/arel/unit/predicates/in_spec.rb +++ b/spec/arel/unit/predicates/in_spec.rb @@ -6,51 +6,79 @@ module Arel @relation = Table.new(:users) @attribute = @relation[:id] end - - describe '#to_sql' do + + describe '#to_sql' do describe 'when relating to an array' do describe 'when the array\'s elements are the same type as the attribute' do before do @array = [1, 2, 3] end - + it 'manufactures sql with a comma separated list' do - In.new(@attribute, @array).to_sql.should be_like(" - `users`.`id` IN (1, 2, 3) - ") + sql = In.new(@attribute, @array).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{`users`.`id` IN (1, 2, 3)}) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{"users"."id" IN (1, 2, 3)}) + end end end - + describe 'when the array\'s elements are not same type as the attribute' do before do @array = ['1-asdf', 2, 3] end - + it 'formats values in the array as the type of the attribute' do - In.new(@attribute, @array).to_sql.should be_like(" - `users`.`id` IN (1, 2, 3) - ") + sql = In.new(@attribute, @array).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{`users`.`id` IN (1, 2, 3)}) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{"users"."id" IN (1, 2, 3)}) + end end end end - + describe 'when relating to a range' do before do @range = 1..2 end - + it 'manufactures sql with a between' do - In.new(@attribute, @range).to_sql.should be_like(" - `users`.`id` BETWEEN 1 AND 2 - ") + sql = In.new(@attribute, @range).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{`users`.`id` BETWEEN 1 AND 2}) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{"users"."id" BETWEEN 1 AND 2}) + end end end - + describe 'when relating to a relation' do it 'manufactures sql with a subselect' do - In.new(@attribute, @relation).to_sql.should be_like(" - `users`.`id` IN (SELECT `users`.`id`, `users`.`name` FROM `users`) - ") + sql = In.new(@attribute, @relation).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + `users`.`id` IN (SELECT `users`.`id`, `users`.`name` FROM `users`) + }) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{ + "users"."id" IN (SELECT "users"."id", "users"."name" FROM "users") + }) + end end end end |