diff options
Diffstat (limited to 'spec/engines')
-rw-r--r-- | spec/engines/memory/integration/joins/cross_engine_spec.rb | 7 | ||||
-rw-r--r-- | spec/engines/sql/unit/predicates/in_spec.rb | 6 | ||||
-rw-r--r-- | spec/engines/sql/unit/relations/having_spec.rb | 33 |
3 files changed, 37 insertions, 9 deletions
diff --git a/spec/engines/memory/integration/joins/cross_engine_spec.rb b/spec/engines/memory/integration/joins/cross_engine_spec.rb index 606f3154c7..5dc1a6cb99 100644 --- a/spec/engines/memory/integration/joins/cross_engine_spec.rb +++ b/spec/engines/memory/integration/joins/cross_engine_spec.rb @@ -13,10 +13,9 @@ module Arel @photos.insert(@photos[:id] => 1, @photos[:user_id] => 1, @photos[:camera_id] => 6) @photos.insert(@photos[:id] => 2, @photos[:user_id] => 2, @photos[:camera_id] => 42) # Oracle adapter returns database integers as Ruby integers and not strings - @adapter_returns_integer = false - adapter_is :oracle do - @adapter_returns_integer = true - end + # So does the FFI sqlite library + db_int_return = @photos.project(@photos[:camera_id]).first.tuple.first + @adapter_returns_integer = db_int_return.is_a?(String) ? false : true end describe 'when the in memory relation is on the left' do diff --git a/spec/engines/sql/unit/predicates/in_spec.rb b/spec/engines/sql/unit/predicates/in_spec.rb index f62ee6e829..be311f9f83 100644 --- a/spec/engines/sql/unit/predicates/in_spec.rb +++ b/spec/engines/sql/unit/predicates/in_spec.rb @@ -137,11 +137,7 @@ module Arel end adapter_is :sqlite3 do - if RUBY_VERSION < '1.9' - sql.should be_like(%Q{"developers"."created_at" BETWEEN '2010-01-01 00:00:00.000000' AND '2010-02-01 00:00:00.000000'}) - else - sql.should be_like(%Q{"developers"."created_at" BETWEEN '2010-01-01 00:00:00' AND '2010-02-01 00:00:00'}) - end + sql.should match(/"developers"."created_at" BETWEEN '2010-01-01 00:00:00(?:\.\d+)' AND '2010-02-01 00:00:00(?:\.\d+)'/) end adapter_is :postgresql do diff --git a/spec/engines/sql/unit/relations/having_spec.rb b/spec/engines/sql/unit/relations/having_spec.rb index fe6f3cc520..a7f2f0da96 100644 --- a/spec/engines/sql/unit/relations/having_spec.rb +++ b/spec/engines/sql/unit/relations/having_spec.rb @@ -39,6 +39,39 @@ module Arel end end end + + describe 'when given two predicates' do + it "manufactures sql with where clause conditions joined by AND" do + sql = @relation.group(@relation[:department]).having("MIN(salary) > 1000", "MAX(salary) < 10000").to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT `developers`.`id`, `developers`.`name`, `developers`.`salary`, `developers`.`department`, `developers`.`created_at` + FROM `developers` + GROUP BY `developers`.`department` + HAVING MIN(salary) > 1000 AND MAX(salary) < 10000 + }) + end + + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "DEVELOPERS"."ID", "DEVELOPERS"."NAME", "DEVELOPERS"."SALARY", "DEVELOPERS"."DEPARTMENT", "DEVELOPERS"."CREATED_AT" + FROM "DEVELOPERS" + GROUP BY "DEVELOPERS"."DEPARTMENT" + HAVING MIN(salary) > 1000 AND MAX(salary) < 10000 + }) + end + + adapter_is_not :mysql, :oracle do + sql.should be_like(%Q{ + SELECT "developers"."id", "developers"."name", "developers"."salary", "developers"."department", "developers"."created_at" + FROM "developers" + GROUP BY "developers"."department" + HAVING MIN(salary) > 1000 AND MAX(salary) < 10000 + }) + end + end + end end end end |