aboutsummaryrefslogtreecommitdiffstats
path: root/spec/arel/unit/relations
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2009-05-16 21:13:32 -0400
committerBryan Helmkamp <bryan@brynary.com>2009-05-17 13:17:07 -0400
commit49d119ae84bbb7cd180ca855cf48997dc731554c (patch)
tree3bae397d3e2b5ee76bd89a87ccbf421d814fec74 /spec/arel/unit/relations
parent4096d192a1e7cdf0115f5a4cf33d102b176cb8cd (diff)
downloadrails-49d119ae84bbb7cd180ca855cf48997dc731554c.tar.gz
rails-49d119ae84bbb7cd180ca855cf48997dc731554c.tar.bz2
rails-49d119ae84bbb7cd180ca855cf48997dc731554c.zip
Adding spec:mysql and spec:sqlite3 tasks
Diffstat (limited to 'spec/arel/unit/relations')
-rw-r--r--spec/arel/unit/relations/alias_spec.rb30
-rw-r--r--spec/arel/unit/relations/delete_spec.rb57
-rw-r--r--spec/arel/unit/relations/group_spec.rb48
-rw-r--r--spec/arel/unit/relations/insert_spec.rb75
-rw-r--r--spec/arel/unit/relations/join_spec.rb52
-rw-r--r--spec/arel/unit/relations/order_spec.rb101
-rw-r--r--spec/arel/unit/relations/project_spec.rb89
-rw-r--r--spec/arel/unit/relations/skip_spec.rb22
-rw-r--r--spec/arel/unit/relations/table_spec.rb41
-rw-r--r--spec/arel/unit/relations/take_spec.rb22
-rw-r--r--spec/arel/unit/relations/update_spec.rb95
-rw-r--r--spec/arel/unit/relations/where_spec.rb44
12 files changed, 504 insertions, 172 deletions
diff --git a/spec/arel/unit/relations/alias_spec.rb b/spec/arel/unit/relations/alias_spec.rb
index 460a0ed0df..570f315892 100644
--- a/spec/arel/unit/relations/alias_spec.rb
+++ b/spec/arel/unit/relations/alias_spec.rb
@@ -16,19 +16,33 @@ module Arel
describe '#to_sql' do
describe 'when there is no ambiguity' do
it 'does not alias table names anywhere a table name can appear' do
- @relation \
+ sql = @relation \
.where(@relation[:id].eq(1)) \
.order(@relation[:id]) \
.project(@relation[:id]) \
.group(@relation[:id]) \
.alias \
- .to_sql.should be_like("
- SELECT `users`.`id`
- FROM `users`
- WHERE `users`.`id` = 1
- GROUP BY `users`.`id`
- ORDER BY `users`.`id`
- ")
+ .to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`
+ FROM `users`
+ WHERE `users`.`id` = 1
+ GROUP BY `users`.`id`
+ ORDER BY `users`.`id`
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id"
+ FROM "users"
+ WHERE "users"."id" = 1
+ GROUP BY "users"."id"
+ ORDER BY "users"."id"
+ })
+ end
end
end
end
diff --git a/spec/arel/unit/relations/delete_spec.rb b/spec/arel/unit/relations/delete_spec.rb
index fa887d20fd..3798178ccc 100644
--- a/spec/arel/unit/relations/delete_spec.rb
+++ b/spec/arel/unit/relations/delete_spec.rb
@@ -8,26 +8,55 @@ module Arel
describe '#to_sql' do
it 'manufactures sql deleting a table relation' do
- Deletion.new(@relation).to_sql.should be_like("
- DELETE
- FROM `users`
- ")
+ sql = Deletion.new(@relation).to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{DELETE FROM `users`})
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{DELETE FROM "users"})
+ end
end
it 'manufactures sql deleting a where relation' do
- Deletion.new(@relation.where(@relation[:id].eq(1))).to_sql.should be_like("
- DELETE
- FROM `users`
- WHERE `users`.`id` = 1
- ")
+ sql = Deletion.new(@relation.where(@relation[:id].eq(1))).to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ DELETE
+ FROM `users`
+ WHERE `users`.`id` = 1
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ DELETE
+ FROM "users"
+ WHERE "users"."id" = 1
+ })
+ end
end
it "manufactures sql deleting a ranged relation" do
- Deletion.new(@relation.take(1)).to_sql.should be_like("
- DELETE
- FROM `users`
- LIMIT 1
- ")
+ sql = Deletion.new(@relation.take(1)).to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ DELETE
+ FROM `users`
+ LIMIT 1
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ DELETE
+ FROM "users"
+ LIMIT 1
+ })
+ end
end
end
diff --git a/spec/arel/unit/relations/group_spec.rb b/spec/arel/unit/relations/group_spec.rb
index a0147b9416..658c0ad406 100644
--- a/spec/arel/unit/relations/group_spec.rb
+++ b/spec/arel/unit/relations/group_spec.rb
@@ -6,25 +6,49 @@ module Arel
@relation = Table.new(:users)
@attribute = @relation[:id]
end
-
+
describe '#to_sql' do
describe 'when given a predicate' do
it "manufactures sql with where clause conditions" do
- Group.new(@relation, @attribute).to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`
- FROM `users`
- GROUP BY `users`.`id`
- ")
+ sql = Group.new(@relation, @attribute).to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ GROUP BY `users`.`id`
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name"
+ FROM "users"
+ GROUP BY "users"."id"
+ })
+ end
end
end
-
+
describe 'when given a string' do
it "passes the string through to the where clause" do
- Group.new(@relation, 'asdf').to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`
- FROM `users`
- GROUP BY asdf
- ")
+ sql = Group.new(@relation, 'asdf').to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ GROUP BY asdf
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name"
+ FROM "users"
+ GROUP BY asdf
+ })
+ end
end
end
end
diff --git a/spec/arel/unit/relations/insert_spec.rb b/spec/arel/unit/relations/insert_spec.rb
index 441c97b290..2fd07dd96c 100644
--- a/spec/arel/unit/relations/insert_spec.rb
+++ b/spec/arel/unit/relations/insert_spec.rb
@@ -8,24 +8,35 @@ module Arel
describe '#to_sql' do
it 'manufactures sql inserting data when given multiple rows' do
- pending 'it should insert multiple rows'
- @insertion = Insert.new(@relation, [@relation[:name] => "nick", @relation[:name] => "bryan"])
+ pending 'it should insert multiple rows' do
+ @insertion = Insert.new(@relation, [@relation[:name] => "nick", @relation[:name] => "bryan"])
- @insertion.to_sql.should be_like("
- INSERT
- INTO `users`
- (`name`) VALUES ('nick'), ('bryan')
- ")
+ @insertion.to_sql.should be_like("
+ INSERT
+ INTO `users`
+ (`name`) VALUES ('nick'), ('bryan')
+ ")
+ end
end
it 'manufactures sql inserting data when given multiple values' do
@insertion = Insert.new(@relation, @relation[:id] => "1", @relation[:name] => "nick")
- @insertion.to_sql.should be_like("
- INSERT
- INTO `users`
- (`id`, `name`) VALUES (1, 'nick')
- ")
+ adapter_is :mysql do
+ @insertion.to_sql.should be_like(%Q{
+ INSERT
+ INTO `users`
+ (`id`, `name`) VALUES (1, 'nick')
+ })
+ end
+
+ adapter_is_not :mysql do
+ @insertion.to_sql.should be_like(%Q{
+ INSERT
+ INTO "users"
+ ("id", "name") VALUES (1, 'nick')
+ })
+ end
end
describe 'when given values whose types correspond to the types of the attributes' do
@@ -34,11 +45,21 @@ module Arel
end
it 'manufactures sql inserting data' do
- @insertion.to_sql.should be_like("
- INSERT
- INTO `users`
- (`name`) VALUES ('nick')
- ")
+ adapter_is :mysql do
+ @insertion.to_sql.should be_like(%Q{
+ INSERT
+ INTO `users`
+ (`name`) VALUES ('nick')
+ })
+ end
+
+ adapter_is_not :mysql do
+ @insertion.to_sql.should be_like(%Q{
+ INSERT
+ INTO "users"
+ ("name") VALUES ('nick')
+ })
+ end
end
end
@@ -48,11 +69,21 @@ module Arel
end
it 'manufactures sql inserting data' do
- @insertion.to_sql.should be_like("
- INSERT
- INTO `users`
- (`id`) VALUES (1)
- ")
+ adapter_is :mysql do
+ @insertion.to_sql.should be_like(%Q{
+ INSERT
+ INTO `users`
+ (`id`) VALUES (1)
+ })
+ end
+
+ adapter_is_not :mysql do
+ @insertion.to_sql.should be_like(%Q{
+ INSERT
+ INTO "users"
+ ("id") VALUES (1)
+ })
+ end
end
end
end
diff --git a/spec/arel/unit/relations/join_spec.rb b/spec/arel/unit/relations/join_spec.rb
index 1698bf9647..fa6bbbe216 100644
--- a/spec/arel/unit/relations/join_spec.rb
+++ b/spec/arel/unit/relations/join_spec.rb
@@ -7,20 +7,20 @@ module Arel
@relation2 = Table.new(:photos)
@predicate = @relation1[:id].eq(@relation2[:user_id])
end
-
+
describe 'hashing' do
it 'implements hash equality' do
Join.new("INNER JOIN", @relation1, @relation2, @predicate) \
.should hash_the_same_as(Join.new("INNER JOIN", @relation1, @relation2, @predicate))
end
end
-
+
describe '#engine' do
it "delegates to a relation's engine" do
Join.new("INNER JOIN", @relation1, @relation2, @predicate).engine.should == @relation1.engine
end
end
-
+
describe '#attributes' do
it 'combines the attributes of the two relations' do
join = Join.new("INNER JOIN", @relation1, @relation2, @predicate)
@@ -32,21 +32,45 @@ module Arel
describe '#to_sql' do
describe 'when joining with another relation' do
it 'manufactures sql joining the two tables on the predicate' do
- Join.new("INNER JOIN", @relation1, @relation2, @predicate).to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`, `photos`.`id`, `photos`.`user_id`, `photos`.`camera_id`
- FROM `users`
- INNER JOIN `photos` ON `users`.`id` = `photos`.`user_id`
- ")
+ sql = Join.new("INNER JOIN", @relation1, @relation2, @predicate).to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`, `photos`.`id`, `photos`.`user_id`, `photos`.`camera_id`
+ FROM `users`
+ INNER JOIN `photos` ON `users`.`id` = `photos`.`user_id`
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name", "photos"."id", "photos"."user_id", "photos"."camera_id"
+ FROM "users"
+ INNER JOIN "photos" ON "users"."id" = "photos"."user_id"
+ })
+ end
end
end
-
+
describe 'when joining with a string' do
it "passes the string through to the where clause" do
- Join.new("INNER JOIN asdf ON fdsa", @relation1).to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`
- FROM `users`
- INNER JOIN asdf ON fdsa
- ")
+ sql = Join.new("INNER JOIN asdf ON fdsa", @relation1).to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ INNER JOIN asdf ON fdsa
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name"
+ FROM "users"
+ INNER JOIN asdf ON fdsa
+ })
+ end
end
end
end
diff --git a/spec/arel/unit/relations/order_spec.rb b/spec/arel/unit/relations/order_spec.rb
index d373a8ba12..31014ddd39 100644
--- a/spec/arel/unit/relations/order_spec.rb
+++ b/spec/arel/unit/relations/order_spec.rb
@@ -10,57 +10,104 @@ module Arel
describe '#to_sql' do
describe "when given an attribute" do
it "manufactures sql with an order clause populated by the attribute" do
- Order.new(@relation, @attribute).to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`
- FROM `users`
- ORDER BY `users`.`id`
- ")
+ sql = Order.new(@relation, @attribute).to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ ORDER BY `users`.`id`
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name"
+ FROM "users"
+ ORDER BY "users"."id"
+ })
+ end
end
end
-
+
describe "when given multiple attributes" do
before do
@another_attribute = @relation[:name]
end
-
+
it "manufactures sql with an order clause populated by comma-separated attributes" do
- Order.new(@relation, @attribute, @another_attribute).to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`
- FROM `users`
- ORDER BY `users`.`id`, `users`.`name`
- ")
+ sql = Order.new(@relation, @attribute, @another_attribute).to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ ORDER BY `users`.`id`, `users`.`name`
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name"
+ FROM "users"
+ ORDER BY "users"."id", "users"."name"
+ })
+ end
end
end
-
+
describe "when given a string" do
before do
@string = "asdf"
end
-
+
it "passes the string through to the order clause" do
- Order.new(@relation, @string).to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`
- FROM `users`
- ORDER BY asdf
- ")
+ sql = Order.new(@relation, @string).to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ ORDER BY asdf
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name"
+ FROM "users"
+ ORDER BY asdf
+ })
+ end
end
end
-
+
describe "when ordering an ordered relation" do
before do
@ordered_relation = Order.new(@relation, @attribute)
@another_attribute = @relation[:name]
end
-
+
it "manufactures sql with the order clause of the last ordering preceding the first ordering" do
- Order.new(@ordered_relation, @another_attribute).to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`
- FROM `users`
- ORDER BY `users`.`name`, `users`.`id`
- ")
+ sql = Order.new(@ordered_relation, @another_attribute).to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ ORDER BY `users`.`name`, `users`.`id`
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name"
+ FROM "users"
+ ORDER BY "users"."name", "users"."id"
+ })
+ end
end
end
end
end
end
- \ No newline at end of file
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
diff --git a/spec/arel/unit/relations/skip_spec.rb b/spec/arel/unit/relations/skip_spec.rb
index d83c969aa8..0653d795b1 100644
--- a/spec/arel/unit/relations/skip_spec.rb
+++ b/spec/arel/unit/relations/skip_spec.rb
@@ -9,11 +9,23 @@ module Arel
describe '#to_sql' do
it "manufactures sql with limit and offset" do
- Skip.new(@relation, @skipped).to_s.should be_like("
- SELECT `users`.`id`, `users`.`name`
- FROM `users`
- OFFSET #{@skipped}
- ")
+ sql = Skip.new(@relation, @skipped).to_s
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ OFFSET 4
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name"
+ FROM "users"
+ OFFSET 4
+ })
+ end
end
end
end
diff --git a/spec/arel/unit/relations/table_spec.rb b/spec/arel/unit/relations/table_spec.rb
index 54520bf3b6..08486c7b6c 100644
--- a/spec/arel/unit/relations/table_spec.rb
+++ b/spec/arel/unit/relations/table_spec.rb
@@ -5,7 +5,7 @@ module Arel
before do
@relation = Table.new(:users)
end
-
+
describe '[]' do
describe 'when given a', Symbol do
it "manufactures an attribute if the symbol names an attribute within the relation" do
@@ -18,39 +18,50 @@ module Arel
it "returns the attribute if the attribute is within the relation" do
@relation[@relation[:id]].should == @relation[:id]
end
-
+
it "returns nil if the attribtue is not within the relation" do
another_relation = Table.new(:photos)
@relation[another_relation[:id]].should be_nil
end
end
-
+
describe 'when given an', Expression do
before do
@expression = @relation[:id].count
end
-
+
it "returns the Expression if the Expression is within the relation" do
@relation[@expression].should be_nil
end
end
end
-
+
describe '#to_sql' do
it "manufactures a simple select query" do
- @relation.to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`
- FROM `users`
- ")
+ sql = @relation.to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name"
+ FROM "users"
+ })
+ end
end
end
-
+
describe '#column_for' do
it "returns the column corresponding to the attribute" do
@relation.column_for(@relation[:id]).should == @relation.columns.detect { |c| c.name == 'id' }
end
end
-
+
describe '#attributes' do
it 'manufactures attributes corresponding to columns in the table' do
@relation.attributes.should == [
@@ -58,7 +69,7 @@ module Arel
Attribute.new(@relation, :name)
]
end
-
+
describe '#reset' do
it "reloads columns from the database" do
lambda { stub(@relation.engine).columns { [] } }.should_not change { @relation.attributes }
@@ -66,20 +77,20 @@ module Arel
end
end
end
-
+
describe 'hashing' do
it "implements hash equality" do
Table.new(:users).should hash_the_same_as(Table.new(:users))
Table.new(:users).should_not hash_the_same_as(Table.new(:photos))
end
end
-
+
describe '#engine' do
it "defaults to global engine" do
Table.engine = engine = Engine.new
Table.new(:users).engine.should == engine
end
-
+
it "can be specified" do
Table.new(:users, engine = Engine.new).engine.should == engine
end
diff --git a/spec/arel/unit/relations/take_spec.rb b/spec/arel/unit/relations/take_spec.rb
index dca7806057..911b84e01e 100644
--- a/spec/arel/unit/relations/take_spec.rb
+++ b/spec/arel/unit/relations/take_spec.rb
@@ -9,11 +9,23 @@ module Arel
describe '#to_sql' do
it "manufactures sql with limit and offset" do
- Take.new(@relation, @taken).to_s.should be_like("
- SELECT `users`.`id`, `users`.`name`
- FROM `users`
- LIMIT #{@taken}
- ")
+ sql = Take.new(@relation, @taken).to_s
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ LIMIT 4
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name"
+ FROM "users"
+ LIMIT 4
+ })
+ end
end
end
end
diff --git a/spec/arel/unit/relations/update_spec.rb b/spec/arel/unit/relations/update_spec.rb
index b67369251f..0bbc9113c6 100644
--- a/spec/arel/unit/relations/update_spec.rb
+++ b/spec/arel/unit/relations/update_spec.rb
@@ -8,18 +8,41 @@ module Arel
describe '#to_sql' do
it "manufactures sql updating attributes when given multiple attributes" do
- Update.new(@relation, @relation[:id] => 1, @relation[:name] => "nick").to_sql.should be_like("
- UPDATE `users`
- SET `id` = 1, `name` = 'nick'
- ")
+ sql = Update.new(@relation, @relation[:id] => 1, @relation[:name] => "nick").to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ UPDATE `users`
+ SET `id` = 1, `name` = 'nick'
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ UPDATE "users"
+ SET "id" = 1, "name" = 'nick'
+ })
+ end
end
it "manufactures sql updating attributes when given a ranged relation" do
- Update.new(@relation.take(1), @relation[:name] => "nick").to_sql.should be_like("
- UPDATE `users`
- SET `name` = 'nick'
- LIMIT 1
- ")
+ sql = Update.new(@relation.take(1), @relation[:name] => "nick").to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ UPDATE `users`
+ SET `name` = 'nick'
+ LIMIT 1
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ UPDATE "users"
+ SET "name" = 'nick'
+ LIMIT 1
+ })
+ end
end
describe 'when given values whose types correspond to the types of the attributes' do
@@ -28,10 +51,19 @@ module Arel
end
it 'manufactures sql updating attributes' do
- @update.to_sql.should be_like("
- UPDATE `users`
- SET `name` = 'nick'
- ")
+ adapter_is :mysql do
+ @update.to_sql.should be_like(%Q{
+ UPDATE `users`
+ SET `name` = 'nick'
+ })
+ end
+
+ adapter_is_not :mysql do
+ @update.to_sql.should be_like(%Q{
+ UPDATE "users"
+ SET "name" = 'nick'
+ })
+ end
end
end
@@ -41,10 +73,19 @@ module Arel
end
it 'manufactures sql updating attributes' do
- @update.to_sql.should be_like("
- UPDATE `users`
- SET `id` = 1
- ")
+ adapter_is :mysql do
+ @update.to_sql.should be_like(%Q{
+ UPDATE `users`
+ SET `id` = 1
+ })
+ end
+
+ adapter_is_not :mysql do
+ @update.to_sql.should be_like(%Q{
+ UPDATE "users"
+ SET "id" = 1
+ })
+ end
end
end
@@ -57,11 +98,21 @@ module Arel
end
it 'manufactures sql updating a where relation' do
- @update.to_sql.should be_like("
- UPDATE `users`
- SET `name` = 'nick'
- WHERE `users`.`id` = 1
- ")
+ adapter_is :mysql do
+ @update.to_sql.should be_like(%Q{
+ UPDATE `users`
+ SET `name` = 'nick'
+ WHERE `users`.`id` = 1
+ })
+ end
+
+ adapter_is_not :mysql do
+ @update.to_sql.should be_like(%Q{
+ UPDATE "users"
+ SET "name" = 'nick'
+ WHERE "users"."id" = 1
+ })
+ end
end
end
end
diff --git a/spec/arel/unit/relations/where_spec.rb b/spec/arel/unit/relations/where_spec.rb
index 8ef4d54b63..64f97c8135 100644
--- a/spec/arel/unit/relations/where_spec.rb
+++ b/spec/arel/unit/relations/where_spec.rb
@@ -18,21 +18,45 @@ module Arel
describe '#to_sql' do
describe 'when given a predicate' do
it "manufactures sql with where clause conditions" do
- Where.new(@relation, @predicate).to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`
- FROM `users`
- WHERE `users`.`id` = 1
- ")
+ sql = Where.new(@relation, @predicate).to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ WHERE `users`.`id` = 1
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name"
+ FROM "users"
+ WHERE "users"."id" = 1
+ })
+ end
end
end
describe 'when given a string' do
it "passes the string through to the where clause" do
- Where.new(@relation, 'asdf').to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`
- FROM `users`
- WHERE asdf
- ")
+ sql = Where.new(@relation, 'asdf').to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ WHERE asdf
+ })
+ end
+
+ adapter_is_not :mysql do
+ sql.should be_like(%Q{
+ SELECT "users"."id", "users"."name"
+ FROM "users"
+ WHERE asdf
+ })
+ end
end
end
end