aboutsummaryrefslogtreecommitdiffstats
path: root/spec/active_relation/relations/join_spec.rb
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-27 16:44:32 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-27 16:44:32 -0800
commit9c4403f67a8f2ac40fc0c964d8c24ecc6c6d7f27 (patch)
treebe9f3ad7e6c9a423b91ff7035f57d7a18b7d1e83 /spec/active_relation/relations/join_spec.rb
parent3f50d5c23719b6877124fcd9669bbf4811f4c2eb (diff)
downloadrails-9c4403f67a8f2ac40fc0c964d8c24ecc6c6d7f27.tar.gz
rails-9c4403f67a8f2ac40fc0c964d8c24ecc6c6d7f27.tar.bz2
rails-9c4403f67a8f2ac40fc0c964d8c24ecc6c6d7f27.zip
cleanup
Diffstat (limited to 'spec/active_relation/relations/join_spec.rb')
-rw-r--r--spec/active_relation/relations/join_spec.rb23
1 files changed, 13 insertions, 10 deletions
diff --git a/spec/active_relation/relations/join_spec.rb b/spec/active_relation/relations/join_spec.rb
index 422a93772d..0f30d11f98 100644
--- a/spec/active_relation/relations/join_spec.rb
+++ b/spec/active_relation/relations/join_spec.rb
@@ -7,7 +7,7 @@ module ActiveRelation
@relation2 = Table.new(:bar)
@predicate = Equality.new(@relation1[:id], @relation2[:id])
end
-
+
describe '==' do
it 'obtains if the two relations and the predicate are identical' do
Join.new("INNER JOIN", @relation1, @relation2, @predicate).should == Join.new("INNER JOIN", @relation1, @relation2, @predicate)
@@ -18,14 +18,14 @@ module ActiveRelation
Join.new("INNER JOIN", @relation1, @relation2, @predicate).should == Join.new("INNER JOIN", @relation2, @relation1, @predicate)
end
end
-
+
describe '#qualify' do
it 'distributes over the relations and predicates' do
Join.new("INNER JOIN", @relation1, @relation2, @predicate).qualify. \
should == Join.new("INNER JOIN", @relation1.qualify, @relation2.qualify, @predicate.qualify)
end
end
-
+
describe '#attributes' do
describe 'with simple relations' do
it 'combines the attributes of the two relations' do
@@ -33,13 +33,14 @@ module ActiveRelation
@relation1.attributes + @relation2.attributes
end
end
-
+
describe 'with aggregated relations' do
it '' do
+ pending
end
end
end
-
+
describe '#to_sql' do
describe 'with simple relations' do
it 'manufactures sql joining the two tables on the predicate' do
@@ -49,7 +50,7 @@ module ActiveRelation
INNER JOIN `bar` ON `foo`.`id` = `bar`.`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("""
@@ -61,7 +62,8 @@ module ActiveRelation
""")
end
end
-
+
+
describe 'aggregated relations' do
before do
@relation = Table.new(:users)
@@ -70,7 +72,7 @@ module ActiveRelation
.group(photos[:user_id]).as(:photo_count)
@predicate = Equality.new(@aggregate_relation[:user_id], @relation[:id])
end
-
+
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("""
@@ -81,9 +83,10 @@ module ActiveRelation
""")
end
end
-
+
describe 'with the aggregation on the left' do
it 'manufactures sql joining the right table to a derived table' do
+ pending
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`
FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photo_count`
@@ -92,7 +95,7 @@ module ActiveRelation
""")
end
end
-
+
it "keeps selects on the aggregation within the derived table" do
pending
Join.new("INNER JOIN", @relation, @aggregate_relation.select(@aggregate_relation[:user_id].equals(1)), @predicate).to_sql.should be_like("""