aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-20 10:11:07 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-20 10:11:07 -0700
commit41f80e494af3ce7c8f3d6aa34f8303524a48373b (patch)
tree30b458021856fe436af8b17a457353356b286f1c /spec
parent2d021c641ab8c9215df863531cfb0d8ff8b9554a (diff)
downloadrails-41f80e494af3ce7c8f3d6aa34f8303524a48373b.tar.gz
rails-41f80e494af3ce7c8f3d6aa34f8303524a48373b.tar.bz2
rails-41f80e494af3ce7c8f3d6aa34f8303524a48373b.zip
limits and offsets need to be externalized too. first draft
Diffstat (limited to 'spec')
-rw-r--r--spec/arel/integration/joins/with_aggregations_spec.rb41
-rw-r--r--spec/arel/unit/relations/project_spec.rb6
2 files changed, 28 insertions, 19 deletions
diff --git a/spec/arel/integration/joins/with_aggregations_spec.rb b/spec/arel/integration/joins/with_aggregations_spec.rb
index 9e28237c3c..d429806094 100644
--- a/spec/arel/integration/joins/with_aggregations_spec.rb
+++ b/spec/arel/integration/joins/with_aggregations_spec.rb
@@ -16,13 +16,22 @@ module Arel
end
describe '#to_sql' do
+ it '' do
+ @relation1.join(@relation2.take(3)).on(@predicate).to_sql.should be_like("
+ SELECT `users`.`id`, `users`.`name`, `photos_external`.`id`, `photos_external`.`user_id`, `photos_external`.`camera_id`
+ FROM `users`
+ INNER JOIN (SELECT `photos`.`id`, `photos`.`user_id`, `photos`.`camera_id` FROM `photos` LIMIT 3) AS `photos_external`
+ ON `users`.`id` = `photos_external`.`user_id`
+ ")
+ end
+
describe 'with the aggregation on the right' do
it 'manufactures sql joining the left table to a derived table' do
@relation1.join(@aggregation).on(@predicate).to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`, `photos_aggregation`.`user_id`, `photos_aggregation`.`cnt`
+ SELECT `users`.`id`, `users`.`name`, `photos_external`.`user_id`, `photos_external`.`cnt`
FROM `users`
- INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_aggregation`
- ON `users`.`id` = `photos_aggregation`.`user_id`
+ INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_external`
+ ON `users`.`id` = `photos_external`.`user_id`
")
end
end
@@ -30,10 +39,10 @@ module Arel
describe 'with the aggregation on the left' do
it 'manufactures sql joining the right table to a derived table' do
@aggregation.join(@relation1).on(@predicate).to_sql.should be_like("
- SELECT `photos_aggregation`.`user_id`, `photos_aggregation`.`cnt`, `users`.`id`, `users`.`name`
- FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_aggregation`
+ SELECT `photos_external`.`user_id`, `photos_external`.`cnt`, `users`.`id`, `users`.`name`
+ FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_external`
INNER JOIN `users`
- ON `users`.`id` = `photos_aggregation`.`user_id`
+ ON `users`.`id` = `photos_external`.`user_id`
")
end
end
@@ -42,10 +51,10 @@ module Arel
it 'it properly aliases the aggregations' do
aggregation2 = @aggregation.alias
@aggregation.join(aggregation2).on(aggregation2[:user_id].eq(@aggregation[:user_id])).to_sql.should be_like("
- SELECT `photos_aggregation`.`user_id`, `photos_aggregation`.`cnt`, `photos_aggregation_2`.`user_id`, `photos_aggregation_2`.`cnt`
- FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_aggregation`
- INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_aggregation_2`
- ON `photos_aggregation_2`.`user_id` = `photos_aggregation`.`user_id`
+ SELECT `photos_external`.`user_id`, `photos_external`.`cnt`, `photos_external_2`.`user_id`, `photos_external_2`.`cnt`
+ FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_external`
+ INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_external_2`
+ ON `photos_external_2`.`user_id` = `photos_external`.`user_id`
")
end
end
@@ -54,10 +63,10 @@ module Arel
describe 'with the aggregation on the left' do
it "manufactures sql keeping wheres on the aggregation within the derived table" do
@relation1.join(@aggregation.where(@aggregation[:user_id].eq(1))).on(@predicate).to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`, `photos_aggregation`.`user_id`, `photos_aggregation`.`cnt`
+ SELECT `users`.`id`, `users`.`name`, `photos_external`.`user_id`, `photos_external`.`cnt`
FROM `users`
- INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` WHERE `photos`.`user_id` = 1 GROUP BY `photos`.`user_id`) AS `photos_aggregation`
- ON `users`.`id` = `photos_aggregation`.`user_id`
+ INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` WHERE `photos`.`user_id` = 1 GROUP BY `photos`.`user_id`) AS `photos_external`
+ ON `users`.`id` = `photos_external`.`user_id`
")
end
end
@@ -65,10 +74,10 @@ module Arel
describe 'with the aggregation on the right' do
it "manufactures sql keeping wheres on the aggregation within the derived table" do
@aggregation.where(@aggregation[:user_id].eq(1)).join(@relation1).on(@predicate).to_sql.should be_like("
- SELECT `photos_aggregation`.`user_id`, `photos_aggregation`.`cnt`, `users`.`id`, `users`.`name`
- FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` WHERE `photos`.`user_id` = 1 GROUP BY `photos`.`user_id`) AS `photos_aggregation`
+ SELECT `photos_external`.`user_id`, `photos_external`.`cnt`, `users`.`id`, `users`.`name`
+ FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` WHERE `photos`.`user_id` = 1 GROUP BY `photos`.`user_id`) AS `photos_external`
INNER JOIN `users`
- ON `users`.`id` = `photos_aggregation`.`user_id`
+ ON `users`.`id` = `photos_external`.`user_id`
")
end
end
diff --git a/spec/arel/unit/relations/project_spec.rb b/spec/arel/unit/relations/project_spec.rb
index 2a4b690dd8..93cbe5668a 100644
--- a/spec/arel/unit/relations/project_spec.rb
+++ b/spec/arel/unit/relations/project_spec.rb
@@ -57,16 +57,16 @@ module Arel
end
end
- describe '#aggregation?' do
+ describe '#externalizable?' do
describe 'when the projections are attributes' do
it 'returns false' do
- Project.new(@relation, @attribute).should_not be_aggregation
+ Project.new(@relation, @attribute).should_not be_externalizable
end
end
describe 'when the projections include an aggregation' do
it "obtains" do
- Project.new(@relation, @attribute.sum).should be_aggregation
+ Project.new(@relation, @attribute.sum).should be_externalizable
end
end
end