aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-04 18:15:38 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-04 18:15:38 -0700
commit6b28dcfa7e03909b69b922e26eb6d3ad8eb3f061 (patch)
treeb05e941417382e1851df6559f870ab48584e61a0 /spec
parent8f87072b1fc2b92328aa45078e535e9575b0b6cf (diff)
downloadrails-6b28dcfa7e03909b69b922e26eb6d3ad8eb3f061.tar.gz
rails-6b28dcfa7e03909b69b922e26eb6d3ad8eb3f061.tar.bz2
rails-6b28dcfa7e03909b69b922e26eb6d3ad8eb3f061.zip
cleanup
Diffstat (limited to 'spec')
-rw-r--r--spec/arel/unit/relations/join_spec.rb104
1 files changed, 51 insertions, 53 deletions
diff --git a/spec/arel/unit/relations/join_spec.rb b/spec/arel/unit/relations/join_spec.rb
index 9cd7a13ed7..d517da8c1f 100644
--- a/spec/arel/unit/relations/join_spec.rb
+++ b/spec/arel/unit/relations/join_spec.rb
@@ -139,79 +139,77 @@ module Arel
@predicate = @relation1[:id].eq(@aliased_relation[:id])
end
- describe 'when joining the same relation to itself' do
- describe '#to_sql' do
- it 'manufactures sql aliasing the table and attributes properly in the join predicate and the where clause' do
- @relation1.join(@aliased_relation).on(@predicate).to_sql.should be_like("
+ describe '#to_sql' do
+ it 'manufactures sql aliasing the table and attributes properly in the join predicate and the where clause' do
+ @relation1.join(@aliased_relation).on(@predicate).to_sql.should be_like("
+ SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`
+ FROM `users`
+ INNER JOIN `users` AS `users_2`
+ ON `users`.`id` = `users_2`.`id`
+ ")
+ end
+
+ describe 'when joining with a selection on the same relation' do
+ it 'manufactures sql aliasing the tables properly' do
+ @relation1 \
+ .join(@aliased_relation.select(@aliased_relation[:id].eq(1))) \
+ .on(@predicate) \
+ .to_sql.should be_like("
SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`
FROM `users`
INNER JOIN `users` AS `users_2`
ON `users`.`id` = `users_2`.`id`
+ WHERE `users_2`.`id` = 1
")
end
+ end
+
+ describe 'when joining the relation to itself multiple times' do
+ before do
+ @relation2 = @relation1.alias
+ @relation3 = @relation1.alias
+ end
- describe 'when joining with a selection on the same relation' do
+ describe 'when joining left-associatively' do
it 'manufactures sql aliasing the tables properly' do
- @relation1 \
- .join(@aliased_relation.select(@aliased_relation[:id].eq(1))) \
- .on(@predicate) \
+ @relation1 \
+ .join(@relation2.join(@relation3).on(@relation2[:id].eq(@relation3[:id]))) \
+ .on(@relation1[:id].eq(@relation2[:id])) \
.to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`
+ SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`, `users_3`.`id`, `users_3`.`name`
FROM `users`
INNER JOIN `users` AS `users_2`
ON `users`.`id` = `users_2`.`id`
- WHERE `users_2`.`id` = 1
+ INNER JOIN `users` AS `users_3`
+ ON `users_2`.`id` = `users_3`.`id`
")
end
end
- describe 'when joining the same relation to itself multiple times' do
- before do
- @relation2 = @relation1.alias
- @relation3 = @relation1.alias
- end
-
- describe 'when joining left-associatively' do
- it 'manufactures sql aliasing the tables properly' do
- @relation1 \
- .join(@relation2.join(@relation3).on(@relation2[:id].eq(@relation3[:id]))) \
- .on(@relation1[:id].eq(@relation2[:id])) \
- .to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`, `users_3`.`id`, `users_3`.`name`
- FROM `users`
- INNER JOIN `users` AS `users_2`
- ON `users`.`id` = `users_2`.`id`
- INNER JOIN `users` AS `users_3`
- ON `users_2`.`id` = `users_3`.`id`
- ")
- end
- end
-
- describe 'when joining right-associatively' do
- it 'manufactures sql aliasing the tables properly' do
- @relation1 \
- .join(@relation2).on(@relation1[:id].eq(@relation2[:id])) \
- .join(@relation3).on(@relation2[:id].eq(@relation3[:id])) \
- .to_sql.should be_like("
- SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`, `users_3`.`id`, `users_3`.`name`
- FROM `users`
- INNER JOIN `users` AS `users_2`
- ON `users`.`id` = `users_2`.`id`
- INNER JOIN `users` AS `users_3`
- ON `users_2`.`id` = `users_3`.`id`
- ")
- end
+ describe 'when joining right-associatively' do
+ it 'manufactures sql aliasing the tables properly' do
+ @relation1 \
+ .join(@relation2).on(@relation1[:id].eq(@relation2[:id])) \
+ .join(@relation3).on(@relation2[:id].eq(@relation3[:id])) \
+ .to_sql.should be_like("
+ SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`, `users_3`.`id`, `users_3`.`name`
+ FROM `users`
+ INNER JOIN `users` AS `users_2`
+ ON `users`.`id` = `users_2`.`id`
+ INNER JOIN `users` AS `users_3`
+ ON `users_2`.`id` = `users_3`.`id`
+ ")
end
end
end
+ end
- describe '[]' do
- describe 'when given an attribute belonging to both sub-relations' do
- it 'disambiguates the relation that serves as the ancestor to the attribute' do
- relation = @relation1.join(@aliased_relation).on(@predicate)
- relation[@relation1[:id]].ancestor.should == @relation1[:id]
- relation[@aliased_relation[:id]].ancestor.should == @aliased_relation[:id]
- end
+ describe '[]' do
+ describe 'when given an attribute belonging to both sub-relations' do
+ it 'disambiguates the relation that serves as the ancestor to the attribute' do
+ relation = @relation1.join(@aliased_relation).on(@predicate)
+ relation[@relation1[:id]].ancestor.should == @relation1[:id]
+ relation[@aliased_relation[:id]].ancestor.should == @aliased_relation[:id]
end
end
end