aboutsummaryrefslogtreecommitdiffstats
path: root/spec/arel/unit/relations/order_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/arel/unit/relations/order_spec.rb')
-rw-r--r--spec/arel/unit/relations/order_spec.rb101
1 files changed, 74 insertions, 27 deletions
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