Permalink
Browse files

Adding spec:mysql and spec:sqlite3 tasks

  • Loading branch information...
brynary committed May 17, 2009
1 parent 4096d19 commit 49d119ae84bbb7cd180ca855cf48997dc731554c
View
@@ -1,3 +1,4 @@
coverage/*
config/database.yml
+spec/fixtures/*database*
*.DS_Store
View
@@ -1,15 +1,31 @@
require 'rubygems'
require 'spec/rake/spectask'
-Spec::Rake::SpecTask.new do |t|
- t.spec_files = FileList['spec/**/*_spec.rb']
-end
+spec_file_list = FileList['spec/**/*_spec.rb']
+desc "Run specs using RCov (uses mysql database adapter)"
Spec::Rake::SpecTask.new(:coverage) do |t|
- t.spec_files = FileList['spec/**/*_spec.rb']
+ t.spec_files =
+ ["spec/connections/mysql_connection.rb"] +
+ spec_file_list
t.rcov = true
t.rcov_opts = ['-x', 'spec,gems']
end
+namespace :spec do
+ for adapter in %w[mysql sqlite3]
+ desc "Run specs with the #{adapter} database adapter"
+ Spec::Rake::SpecTask.new(adapter) do |t|
+ t.spec_files =
+ ["spec/connections/#{adapter}_connection.rb"] +
+ ["spec/schemas/#{adapter}_schema.rb"] +
+ spec_file_list
+ end
+ end
+end
+
+desc "Run specs with mysql and sqlite3 database adapters (default)"
+task :spec => ["spec:sqlite3", "spec:mysql"]
+
desc "Default task is to run specs"
task :default => :spec
@@ -11,39 +11,79 @@ module Arel
describe 'when joining a relation to itself' do
describe '#to_sql' do
it 'manufactures sql aliasing the table and attributes properly in the join predicate and the where clause' do
- @relation1.join(@relation2).on(@predicate).to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`
- FROM `users`
- INNER JOIN `users` AS `users_2`
- ON `users`.`id` = `users_2`.`id`
- ")
- end
+ sql = @relation1.join(@relation2).on(@predicate).to_sql
- describe 'when joining with a where on the same relation' do
- it 'manufactures sql aliasing the tables properly' do
- @relation1 \
- .join(@relation2.where(@relation2[:id].eq(1))) \
- .on(@predicate) \
- .to_sql.should be_like("
+ adapter_is :mysql do
+ sql.should be_like(%Q{
SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`
FROM `users`
INNER JOIN `users` AS `users_2`
- ON `users`.`id` = `users_2`.`id` AND `users_2`.`id` = 1
- ")
+ ON `users`.`id` = `users_2`.`id`
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name", "users_2"."id", "users_2"."name"
+ FROM "users"
+ INNER JOIN "users" AS "users_2"
+ ON "users"."id" = "users_2"."id"
+ })
+ end
+ end
+
+ describe 'when joining with a where on the same relation' do
+ it 'manufactures sql aliasing the tables properly' do
+ sql = @relation1 \
+ .join(@relation2.where(@relation2[:id].eq(1))) \
+ .on(@predicate) \
+ .to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`
+ FROM `users`
+ INNER JOIN `users` AS `users_2`
+ ON `users`.`id` = `users_2`.`id` AND `users_2`.`id` = 1
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name", "users_2"."id", "users_2"."name"
+ FROM "users"
+ INNER JOIN "users" AS "users_2"
+ ON "users"."id" = "users_2"."id" AND "users_2"."id" = 1
+ })
+ end
end
describe 'when the where occurs before the alias' do
it 'manufactures sql aliasing the predicates properly' do
relation2 = @relation1.where(@relation1[:id].eq(1)).alias
- @relation1 \
+
+ sql = @relation1 \
.join(relation2) \
.on(relation2[:id].eq(@relation1[:id])) \
- .to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`
- FROM `users`
- INNER JOIN `users` AS `users_2`
- ON `users_2`.`id` = `users`.`id` AND `users_2`.`id` = 1
- ")
+ .to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`
+ FROM `users`
+ INNER JOIN `users` AS `users_2`
+ ON `users_2`.`id` = `users`.`id` AND `users_2`.`id` = 1
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name", "users_2"."id", "users_2"."name"
+ FROM "users"
+ INNER JOIN "users" AS "users_2"
+ ON "users_2"."id" = "users"."id" AND "users_2"."id" = 1
+ })
+ end
end
end
end
@@ -55,35 +95,65 @@ module Arel
describe 'when joining left-associatively' do
it 'manufactures sql aliasing the tables properly' do
- @relation1 \
+ sql = @relation1 \
.join(@relation2 \
.join(@relation3) \
.on(@relation2[:id].eq(@relation3[:id]))) \
.on(@relation1[:id].eq(@relation2[:id])) \
- .to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`, `users_3`.`id`, `users_3`.`name`
- FROM `users`
- INNER JOIN `users` AS `users_2`
- ON `users`.`id` = `users_2`.`id`
- INNER JOIN `users` AS `users_3`
- ON `users_2`.`id` = `users_3`.`id`
- ")
+ .to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`, `users_3`.`id`, `users_3`.`name`
+ FROM `users`
+ INNER JOIN `users` AS `users_2`
+ ON `users`.`id` = `users_2`.`id`
+ INNER JOIN `users` AS `users_3`
+ ON `users_2`.`id` = `users_3`.`id`
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name", "users_2"."id", "users_2"."name", "users_3"."id", "users_3"."name"
+ FROM "users"
+ INNER JOIN "users" AS "users_2"
+ ON "users"."id" = "users_2"."id"
+ INNER JOIN "users" AS "users_3"
+ ON "users_2"."id" = "users_3"."id"
+ })
+ end
end
end
describe 'when joining right-associatively' do
it 'manufactures sql aliasing the tables properly' do
- @relation1 \
+ sql = @relation1 \
.join(@relation2).on(@relation1[:id].eq(@relation2[:id])) \
.join(@relation3).on(@relation2[:id].eq(@relation3[:id])) \
- .to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`, `users_3`.`id`, `users_3`.`name`
- FROM `users`
- INNER JOIN `users` AS `users_2`
- ON `users`.`id` = `users_2`.`id`
- INNER JOIN `users` AS `users_3`
- ON `users_2`.`id` = `users_3`.`id`
- ")
+ .to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`, `users_3`.`id`, `users_3`.`name`
+ FROM `users`
+ INNER JOIN `users` AS `users_2`
+ ON `users`.`id` = `users_2`.`id`
+ INNER JOIN `users` AS `users_3`
+ ON `users_2`.`id` = `users_3`.`id`
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name", "users_2"."id", "users_2"."name", "users_3"."id", "users_3"."name"
+ FROM "users"
+ INNER JOIN "users" AS "users_2"
+ ON "users"."id" = "users_2"."id"
+ INNER JOIN "users" AS "users_3"
+ ON "users_2"."id" = "users_3"."id"
+ })
+ end
end
end
end
Oops, something went wrong.

0 comments on commit 49d119a

Please sign in to comment.