From 14210279b23788d47a18f0615f5e20234550c8ac Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Sun, 18 May 2008 22:11:05 -0700 Subject: can't remember what i was working on --- .../arel/integration/joins/with_aggregations_spec.rb | 10 ++++++++-- spec/arel/unit/relations/alias_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'spec/arel') diff --git a/spec/arel/integration/joins/with_aggregations_spec.rb b/spec/arel/integration/joins/with_aggregations_spec.rb index db34bb1b46..ab904d103d 100644 --- a/spec/arel/integration/joins/with_aggregations_spec.rb +++ b/spec/arel/integration/joins/with_aggregations_spec.rb @@ -39,8 +39,14 @@ module Arel end describe 'with the aggregation on both sides' do - it '' do - @aggregation.join(@aggregation.alias).on(@predicate).to_sql.should == '' + 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` + ") end end diff --git a/spec/arel/unit/relations/alias_spec.rb b/spec/arel/unit/relations/alias_spec.rb index 96e06f48bc..ce35debadf 100644 --- a/spec/arel/unit/relations/alias_spec.rb +++ b/spec/arel/unit/relations/alias_spec.rb @@ -12,5 +12,25 @@ module Arel (aliaz = Alias.new(@relation)).should == aliaz end end + + describe '#to_sql' do + describe 'when there is no ambiguity' do + it 'does not alias table names anywhere a table name can appear' do + @relation \ + .select(@relation[:id].eq(1)) \ + .order(@relation[:id]) \ + .project(@relation[:id]) \ + .group(@relation[:id]) \ + .alias \ + .to_sql.should be_like(" + SELECT `users`.`id` + FROM `users` + WHERE `users`.`id` = 1 + ORDER BY `users`.`id` + GROUP BY `users`.`id` + ") + end + end + end end end \ No newline at end of file -- cgit v1.2.3