Skip to content
Browse files

Merge branch 'master' of github.com:rails/arel

  • Loading branch information...
2 parents f21f289 + e74bbd6 commit 0c2930cba355607eebb8ead19161a41ec0cec992 @miloops miloops committed Feb 17, 2010
View
2 lib/arel/engines/sql/formatters.rb
@@ -112,7 +112,7 @@ def scalar(scalar)
end
def range(left, right)
- "#{left} AND #{right}"
+ "#{scalar(left)} AND #{scalar(right)}"
end
end
View
24 spec/arel/engines/sql/unit/predicates/in_spec.rb
@@ -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
View
4 spec/arel/engines/sql/unit/relations/having_spec.rb
@@ -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
View
3 spec/schemas/mysql_schema.rb
@@ -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
View
3 spec/schemas/postgresql_schema.rb
@@ -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
View
3 spec/schemas/sqlite3_schema.rb
@@ -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 0c2930c

Please sign in to comment.
Something went wrong with that request. Please try again.