diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-18 16:11:08 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-18 16:11:08 -0700 |
commit | 32ad530b825f4cdac51e579306548ca695471039 (patch) | |
tree | df137bf2e7dfd37d086c3b6b3df291c1b940e23f /spec/arel/integration/joins | |
parent | 7a068384b74813b3ea9a309d237c6ce8e8fde5d6 (diff) | |
download | rails-32ad530b825f4cdac51e579306548ca695471039.tar.gz rails-32ad530b825f4cdac51e579306548ca695471039.tar.bz2 rails-32ad530b825f4cdac51e579306548ca695471039.zip |
rename refactor of circle
Diffstat (limited to 'spec/arel/integration/joins')
-rw-r--r-- | spec/arel/integration/joins/with_adjacency_spec.rb | 18 | ||||
-rw-r--r-- | spec/arel/integration/joins/with_aggregations_spec.rb | 20 |
2 files changed, 21 insertions, 17 deletions
diff --git a/spec/arel/integration/joins/with_adjacency_spec.rb b/spec/arel/integration/joins/with_adjacency_spec.rb index ab63fecb46..222303977f 100644 --- a/spec/arel/integration/joins/with_adjacency_spec.rb +++ b/spec/arel/integration/joins/with_adjacency_spec.rb @@ -97,6 +97,17 @@ module Arel .on(@predicate) \ .should disambiguate_attributes(@relation1[:id], @relation2[:id]) end + + describe 'when both relations are compound and only one is an alias' do + it 'disambiguates the relation that serves as the ancestor to the attribute' do + compound1 = @relation1.select(@predicate) + compound2 = compound1.alias + compound1 \ + .join(compound2) \ + .on(@predicate) \ + .should disambiguate_attributes(compound1[:id], compound2[:id]) + end + end describe 'when the left relation is extremely compound' do it 'disambiguates the relation that serves as the ancestor to the attribute' do @@ -107,13 +118,6 @@ module Arel .on(@predicate) \ .should disambiguate_attributes(@relation1[:id], @relation2[:id]) end - - it '' do - r0 = @relation1.select(@predicate) - r1 = r0.alias - r = r0.join(r1).on(@predicate) - r.should disambiguate_attributes(r0[:id], r1[:id]) - end end describe 'when the right relation is extremely compound' do diff --git a/spec/arel/integration/joins/with_aggregations_spec.rb b/spec/arel/integration/joins/with_aggregations_spec.rb index 655250f4f9..db34bb1b46 100644 --- a/spec/arel/integration/joins/with_aggregations_spec.rb +++ b/spec/arel/integration/joins/with_aggregations_spec.rb @@ -15,16 +15,10 @@ module Arel .project(@relation2[:user_id], @relation2[:id].count.as(:cnt)) \ end - describe '#attributes' do - it '' do - @relation1.join(@aggregation).on(@predicate)[@relation2[:user_id]].should_not be_nil - end - end - describe '#to_sql' do describe 'with the aggregation on the right' do it 'manufactures sql joining the left table to a derived table' do - Join.new("INNER JOIN", @relation1, @aggregation, @predicate).to_sql.should be_like(" + @relation1.join(@aggregation).on(@predicate).to_sql.should be_like(" SELECT `users`.`id`, `users`.`name`, `photos_aggregation`.`user_id`, `photos_aggregation`.`cnt` FROM `users` INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_aggregation` @@ -35,7 +29,7 @@ module Arel describe 'with the aggregation on the left' do it 'manufactures sql joining the right table to a derived table' do - Join.new("INNER JOIN", @aggregation, @relation1, @predicate).to_sql.should be_like(" + @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` INNER JOIN `users` @@ -43,11 +37,17 @@ module Arel ") end end + + describe 'with the aggregation on both sides' do + it '' do + @aggregation.join(@aggregation.alias).on(@predicate).to_sql.should == '' + end + end describe 'when the aggration has a selection' do describe 'with the aggregation on the left' do it "manufactures sql keeping selects on the aggregation within the derived table" do - Join.new("INNER JOIN", @relation1, @aggregation.select(@aggregation[:user_id].eq(1)), @predicate).to_sql.should be_like(" + @relation1.join(@aggregation.select(@aggregation[:user_id].eq(1))).on(@predicate).to_sql.should be_like(" SELECT `users`.`id`, `users`.`name`, `photos_aggregation`.`user_id`, `photos_aggregation`.`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` @@ -58,7 +58,7 @@ module Arel describe 'with the aggregation on the right' do it "manufactures sql keeping selects on the aggregation within the derived table" do - Join.new("INNER JOIN", @aggregation.select(@aggregation[:user_id].eq(1)), @relation1, @predicate).to_sql.should be_like(" + @aggregation.select(@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` INNER JOIN `users` |