diff options
author | Eugene Pimenov <libc@mac.com> | 2010-01-30 13:16:59 +0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-02-01 10:02:21 -0300 |
commit | e74bbd6830f5ca5f0ab1fe9f2f645674f6333a29 (patch) | |
tree | 0a26cf8e28ce188697d2645d54678ab71c336c13 /spec | |
parent | 7ba3758665906599013e892515620431d6494030 (diff) | |
download | rails-e74bbd6830f5ca5f0ab1fe9f2f645674f6333a29.tar.gz rails-e74bbd6830f5ca5f0ab1fe9f2f645674f6333a29.tar.bz2 rails-e74bbd6830f5ca5f0ab1fe9f2f645674f6333a29.zip |
Quoting every part of a Range. Calling .to_s is not enough for Range with two Time objects.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/arel/engines/sql/unit/predicates/in_spec.rb | 24 | ||||
-rw-r--r-- | spec/arel/engines/sql/unit/relations/having_spec.rb | 4 | ||||
-rw-r--r-- | spec/schemas/mysql_schema.rb | 3 | ||||
-rw-r--r-- | spec/schemas/postgresql_schema.rb | 3 | ||||
-rw-r--r-- | spec/schemas/sqlite3_schema.rb | 3 |
5 files changed, 32 insertions, 5 deletions
diff --git a/spec/arel/engines/sql/unit/predicates/in_spec.rb b/spec/arel/engines/sql/unit/predicates/in_spec.rb index 76e5fc58df..a8ae9e4b5f 100644 --- a/spec/arel/engines/sql/unit/predicates/in_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/in_spec.rb @@ -84,6 +84,30 @@ module Arel 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 diff --git a/spec/arel/engines/sql/unit/relations/having_spec.rb b/spec/arel/engines/sql/unit/relations/having_spec.rb index dd170a256f..915ee3af08 100644 --- a/spec/arel/engines/sql/unit/relations/having_spec.rb +++ b/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 diff --git a/spec/schemas/mysql_schema.rb b/spec/schemas/mysql_schema.rb index cb4c746776..a2e913d756 100644 --- a/spec/schemas/mysql_schema.rb +++ b/spec/schemas/mysql_schema.rb @@ -16,7 +16,8 @@ sql = <<-SQL 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 diff --git a/spec/schemas/postgresql_schema.rb b/spec/schemas/postgresql_schema.rb index 8b7dac1c41..23a48f5ad8 100644 --- a/spec/schemas/postgresql_schema.rb +++ b/spec/schemas/postgresql_schema.rb @@ -16,7 +16,8 @@ sql = <<-SQL 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 diff --git a/spec/schemas/sqlite3_schema.rb b/spec/schemas/sqlite3_schema.rb index 9dbb62428e..c1fed70859 100644 --- a/spec/schemas/sqlite3_schema.rb +++ b/spec/schemas/sqlite3_schema.rb @@ -16,7 +16,8 @@ sql = <<-SQL 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 |