aboutsummaryrefslogtreecommitdiffstats
path: root/spec/active_relation/relations/join_spec.rb
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-02-11 22:56:12 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-02-11 22:56:12 -0800
commit29d9b8e9b5899a8c52326dfca9343e79ba049d6b (patch)
tree4ca2605f94ca0d38d8aec1d689ec03713db54996 /spec/active_relation/relations/join_spec.rb
parent61d6c2c1c5215014971355892e024682ed148ebb (diff)
downloadrails-29d9b8e9b5899a8c52326dfca9343e79ba049d6b.tar.gz
rails-29d9b8e9b5899a8c52326dfca9343e79ba049d6b.tar.bz2
rails-29d9b8e9b5899a8c52326dfca9343e79ba049d6b.zip
removing code complexity concerning attribute lookup.
Diffstat (limited to 'spec/active_relation/relations/join_spec.rb')
-rw-r--r--spec/active_relation/relations/join_spec.rb26
1 files changed, 13 insertions, 13 deletions
diff --git a/spec/active_relation/relations/join_spec.rb b/spec/active_relation/relations/join_spec.rb
index 2df349dcd3..3b2ad88123 100644
--- a/spec/active_relation/relations/join_spec.rb
+++ b/spec/active_relation/relations/join_spec.rb
@@ -3,8 +3,8 @@ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
module ActiveRelation
describe Join do
before do
- @relation1 = Table.new(:foo)
- @relation2 = Table.new(:bar)
+ @relation1 = Table.new(:users)
+ @relation2 = Table.new(:photos)
@predicate = Equality.new(@relation1[:id], @relation2[:id])
end
@@ -55,20 +55,20 @@ module ActiveRelation
describe 'with simple relations' do
it 'manufactures sql joining the two tables on the predicate' do
Join.new("INNER JOIN", @relation1, @relation2, @predicate).to_sql.should be_like("""
- SELECT `foo`.`name`, `foo`.`id`, `bar`.`name`, `bar`.`foo_id`, `bar`.`id`
- FROM `foo`
- INNER JOIN `bar` ON `foo`.`id` = `bar`.`id`
+ SELECT `users`.`id`, `users`.`name`, `photos`.`id`, `photos`.`user_id`, `photos`.`camera_id`
+ FROM `users`
+ INNER JOIN `photos` ON `users`.`id` = `photos`.`id`
""")
end
it 'manufactures sql joining the two tables, merging any selects' do
Join.new("INNER JOIN", @relation1.select(@relation1[:id].equals(1)),
@relation2.select(@relation2[:id].equals(2)), @predicate).to_sql.should be_like("""
- SELECT `foo`.`name`, `foo`.`id`, `bar`.`name`, `bar`.`foo_id`, `bar`.`id`
- FROM `foo`
- INNER JOIN `bar` ON `foo`.`id` = `bar`.`id`
- WHERE `foo`.`id` = 1
- AND `bar`.`id` = 2
+ SELECT `users`.`id`, `users`.`name`, `photos`.`id`, `photos`.`user_id`, `photos`.`camera_id`
+ FROM `users`
+ INNER JOIN `photos` ON `users`.`id` = `photos`.`id`
+ WHERE `users`.`id` = 1
+ AND `photos`.`id` = 2
""")
end
end
@@ -84,7 +84,7 @@ module ActiveRelation
describe 'with the aggregation on the right' do
it 'manufactures sql joining the left table to a derived table' do
Join.new("INNER JOIN", @relation, @aggregate_relation, @predicate).to_sql.should be_like("""
- SELECT `users`.`name`, `users`.`id`, `photo_count`.`user_id`, `photo_count`.`cnt`
+ SELECT `users`.`id`, `users`.`name`, `photo_count`.`user_id`, `photo_count`.`cnt`
FROM `users`
INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photo_count`
ON `photo_count`.`user_id` = `users`.`id`
@@ -95,7 +95,7 @@ module ActiveRelation
describe 'with the aggregation on the left' do
it 'manufactures sql joining the right table to a derived table' do
Join.new("INNER JOIN", @aggregate_relation, @relation, @predicate).to_sql.should be_like("""
- SELECT `photo_count`.`user_id`, `photo_count`.`cnt`, `users`.`name`, `users`.`id`
+ SELECT `photo_count`.`user_id`, `photo_count`.`cnt`, `users`.`id`, `users`.`name`
FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photo_count`
INNER JOIN `users`
ON `photo_count`.`user_id` = `users`.`id`
@@ -105,7 +105,7 @@ module ActiveRelation
it "keeps selects on the aggregation within the derived table" do
Join.new("INNER JOIN", @relation, @aggregate_relation.select(@aggregate_relation[:user_id].equals(1)), @predicate).to_sql.should be_like("""
- SELECT `users`.`name`, `users`.`id`, `photo_count`.`user_id`, `photo_count`.`cnt`
+ SELECT `users`.`id`, `users`.`name`, `photo_count`.`user_id`, `photo_count`.`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 `photo_count`
ON `photo_count`.`user_id` = `users`.`id`