diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-18 22:11:05 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-18 22:11:05 -0700 |
commit | 14210279b23788d47a18f0615f5e20234550c8ac (patch) | |
tree | a618279edd1e58b61cb44e213bf6937e5b47ba01 /spec/arel | |
parent | 7feff4e7b52fbef356426d22257af161704315ad (diff) | |
download | rails-14210279b23788d47a18f0615f5e20234550c8ac.tar.gz rails-14210279b23788d47a18f0615f5e20234550c8ac.tar.bz2 rails-14210279b23788d47a18f0615f5e20234550c8ac.zip |
can't remember what i was working on
Diffstat (limited to 'spec/arel')
-rw-r--r-- | spec/arel/integration/joins/with_aggregations_spec.rb | 10 | ||||
-rw-r--r-- | spec/arel/unit/relations/alias_spec.rb | 20 |
2 files changed, 28 insertions, 2 deletions
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 |