aboutsummaryrefslogtreecommitdiffstats
path: root/spec/engines
diff options
context:
space:
mode:
authorErnie Miller <ernie@metautonomo.us>2010-05-21 11:45:12 -0400
committerErnie Miller <ernie@metautonomo.us>2010-05-21 11:45:12 -0400
commit43bfd3fae496a2a859aad0a654a91437357c3450 (patch)
treebd95f3b7add4ba7841a6fa9dd717de9c60ea90a8 /spec/engines
parentd144b8d5af11c819b8f70a97006998bf89ee926c (diff)
downloadrails-43bfd3fae496a2a859aad0a654a91437357c3450.tar.gz
rails-43bfd3fae496a2a859aad0a654a91437357c3450.tar.bz2
rails-43bfd3fae496a2a859aad0a654a91437357c3450.zip
Fix tests to work properly on Ruby 1.9, honor multiple calls to #order in memory engine, and make having clauses behave like where clauses in SQL engine (join with AND, allow multiple calls to having to add predicates)
Diffstat (limited to 'spec/engines')
-rw-r--r--spec/engines/memory/integration/joins/cross_engine_spec.rb7
-rw-r--r--spec/engines/sql/unit/predicates/in_spec.rb6
-rw-r--r--spec/engines/sql/unit/relations/having_spec.rb33
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