Permalink
Browse files

Quoting every part of a Range. Calling .to_s is not enough for Range …

…with two Time objects.
  • Loading branch information...
1 parent 7ba3758 commit e74bbd6830f5ca5f0ab1fe9f2f645674f6333a29 @libc libc committed with miloops Jan 30, 2010
@@ -112,7 +112,7 @@ def scalar(scalar)
end
def range(left, right)
- "#{left} AND #{right}"
+ "#{scalar(left)} AND #{scalar(right)}"
end
end
@@ -84,6 +84,30 @@ module Predicates
end
end
+ describe 'when relating to a time range' do
+ before do
+ @relation = Arel::Table.new(:developers)
+ @attribute = @relation[:created_at]
+ @range = Time.mktime(2010, 01, 01)..Time.mktime(2010, 02, 01)
+ end
+
+ it 'manufactures sql with a between' do
+ sql = In.new(@attribute, @range).to_sql
+
+ adapter_is :mysql do
+ sql.should be_like(%Q{`developers`.`created_at` BETWEEN '2010-01-01 00:00:00' AND '2010-02-01 00:00:00'})
+ end
+
+ adapter_is :sqlite3 do
+ sql.should be_like(%Q{"developers"."created_at" BETWEEN '2010-01-01 00:00:00' AND '2010-02-01 00:00:00'})
+ end
+
+ adapter_is :postgresql do
+ sql.should be_like(%Q{"developers"."created_at" BETWEEN '2010-01-01 00:00:00.000000' AND '2010-02-01 00:00:00.000000'})
+ end
+ end
+ end
+
describe 'when relating to a relation' do
it 'manufactures sql with a subselect' do
sql = In.new(@attribute, @relation).to_sql
@@ -13,7 +13,7 @@ module Arel
adapter_is :mysql do
sql.should be_like(%Q{
- SELECT `developers`.`id`, `developers`.`name`, `developers`.`salary`, `developers`.`department`
+ SELECT `developers`.`id`, `developers`.`name`, `developers`.`salary`, `developers`.`department`, `developers`.`created_at`
FROM `developers`
GROUP BY `developers`.`department`
HAVING MIN(salary) > 1000
@@ -22,7 +22,7 @@ module Arel
adapter_is_not :mysql do
sql.should be_like(%Q{
- SELECT "developers"."id", "developers"."name", "developers"."salary", "developers"."department"
+ SELECT "developers"."id", "developers"."name", "developers"."salary", "developers"."department", "developers"."created_at"
FROM "developers"
GROUP BY "developers"."department"
HAVING MIN(salary) > 1000
@@ -16,7 +16,8 @@
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
salary INTEGER NOT NULL,
- department VARCHAR(255) NOT NULL
+ department VARCHAR(255) NOT NULL,
+ created_at TIMESTAMP NOT NULL
);
SQL
@@ -16,7 +16,8 @@
id SERIAL PRIMARY KEY NOT NULL,
name VARCHAR(255) NOT NULL,
salary INTEGER NOT NULL,
- department VARCHAR(255) NOT NULL
+ department VARCHAR(255) NOT NULL,
+ created_at TIMESTAMP NOT NULL
);
SQL
@@ -16,7 +16,8 @@
id INTEGER NOT NULL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
salary INTEGER NOT NULL,
- department VARCHAR(255) NOT NULL
+ department VARCHAR(255) NOT NULL,
+ created_at TIMESTAMP NOT NULL
);
SQL

0 comments on commit e74bbd6

Please sign in to comment.