diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-27 20:40:20 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-27 20:40:20 -0700 |
commit | 3ae7a601e962468468eac1399ebdfd7113730310 (patch) | |
tree | 548407d22d1799f20366c3a122fb4593002e5063 /spec/arel/unit | |
parent | 4a6822d5e416f2e687d32a14ff98c7b5c815369c (diff) | |
download | rails-3ae7a601e962468468eac1399ebdfd7113730310.tar.gz rails-3ae7a601e962468468eac1399ebdfd7113730310.tar.bz2 rails-3ae7a601e962468468eac1399ebdfd7113730310.zip |
attribute disambiguation
Diffstat (limited to 'spec/arel/unit')
-rw-r--r-- | spec/arel/unit/relations/join_spec.rb | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/spec/arel/unit/relations/join_spec.rb b/spec/arel/unit/relations/join_spec.rb index f9d0d9561e..12b7d7a593 100644 --- a/spec/arel/unit/relations/join_spec.rb +++ b/spec/arel/unit/relations/join_spec.rb @@ -145,14 +145,31 @@ module Arel end describe 'when joining aliased relations' do - it 'aliases the table and attributes properly' do - aliased_relation = @relation1.as(:alias) - @relation1.join(aliased_relation).on(@relation1[:id].eq(aliased_relation[:id])).to_sql.should be_like(" - SELECT `users`.`id`, `users`.`name`, `alias`.`id`, `alias`.`name` - FROM `users` - INNER JOIN `users` AS `alias` - ON `users`.`id` = `alias`.`id` - ") + before do + @aliased_relation = @relation1.as(:alias) + end + + describe '#to_sql' do + it 'aliases the table and attributes properly' do + @relation1.join(@aliased_relation).on(@relation1[:id].eq(@aliased_relation[:id])).to_sql.should be_like(" + SELECT `users`.`id`, `users`.`name`, `alias`.`id`, `alias`.`name` + FROM `users` + INNER JOIN `users` AS `alias` + ON `users`.`id` = `alias`.`id` + ") + end + end + + describe 'when joining the same relation to itself' do + describe '[]' do + describe 'when given an attribute belonging to both sub-relations' do + it '' do + relation = @relation1.join(@aliased_relation).on(@relation1[:id].eq(@aliased_relation[:id])) + relation[@relation1[:id]].ancestor.should == @relation1[:id] + relation[@aliased_relation[:id]].ancestor.should == @aliased_relation[:id] + end + end + end end end |