diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/arel/engines/sql/unit/relations/having_spec.rb | 36 | ||||
-rw-r--r-- | spec/schemas/mysql_schema.rb | 7 | ||||
-rw-r--r-- | spec/schemas/postgresql_schema.rb | 7 | ||||
-rw-r--r-- | spec/schemas/sqlite3_schema.rb | 7 |
4 files changed, 57 insertions, 0 deletions
diff --git a/spec/arel/engines/sql/unit/relations/having_spec.rb b/spec/arel/engines/sql/unit/relations/having_spec.rb new file mode 100644 index 0000000000..dd170a256f --- /dev/null +++ b/spec/arel/engines/sql/unit/relations/having_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +module Arel + describe Having do + before do + @relation = Table.new(:developers) + end + + describe '#to_sql' do + describe 'when given a predicate' do + it "manufactures sql with where clause conditions" do + sql = @relation.group(@relation[:department]).having("MIN(salary) > 1000").to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT `developers`.`id`, `developers`.`name`, `developers`.`salary`, `developers`.`department` + FROM `developers` + GROUP BY `developers`.`department` + HAVING MIN(salary) > 1000 + }) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{ + SELECT "developers"."id", "developers"."name", "developers"."salary", "developers"."department" + FROM "developers" + GROUP BY "developers"."department" + HAVING MIN(salary) > 1000 + }) + end + end + end + end + end +end + diff --git a/spec/schemas/mysql_schema.rb b/spec/schemas/mysql_schema.rb index dc2558fd6a..cb4c746776 100644 --- a/spec/schemas/mysql_schema.rb +++ b/spec/schemas/mysql_schema.rb @@ -11,6 +11,13 @@ sql = <<-SQL user_id INTEGER NOT NULL, camera_id INTEGER NOT NULL ); + DROP TABLE IF EXISTS developers; + CREATE TABLE developers ( + id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + salary INTEGER NOT NULL, + department VARCHAR(255) NOT NULL + ); SQL sql.split(/;/).select(&:present?).each do |sql_statement| diff --git a/spec/schemas/postgresql_schema.rb b/spec/schemas/postgresql_schema.rb index 30fa665902..8b7dac1c41 100644 --- a/spec/schemas/postgresql_schema.rb +++ b/spec/schemas/postgresql_schema.rb @@ -11,6 +11,13 @@ sql = <<-SQL user_id INTEGER NOT NULL, camera_id INTEGER NOT NULL ); + DROP TABLE IF EXISTS developers; + CREATE TABLE developers ( + id SERIAL PRIMARY KEY NOT NULL, + name VARCHAR(255) NOT NULL, + salary INTEGER NOT NULL, + department VARCHAR(255) NOT NULL + ); SQL sql.split(/;/).select(&:present?).each do |sql_statement| diff --git a/spec/schemas/sqlite3_schema.rb b/spec/schemas/sqlite3_schema.rb index 94d224520e..9dbb62428e 100644 --- a/spec/schemas/sqlite3_schema.rb +++ b/spec/schemas/sqlite3_schema.rb @@ -11,6 +11,13 @@ sql = <<-SQL user_id INTEGER NOT NULL, camera_id INTEGER NOT NULL ); + DROP TABLE IF EXISTS developers; + CREATE TABLE developers ( + id INTEGER NOT NULL PRIMARY KEY, + name VARCHAR(255) NOT NULL, + salary INTEGER NOT NULL, + department VARCHAR(255) NOT NULL + ); SQL sql.split(/;/).select(&:present?).each do |sql_statement| |