aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--spec/active_relation/integration/scratch_spec.rb2
-rw-r--r--spec/active_relation/relations/join_spec.rb23
2 files changed, 14 insertions, 11 deletions
diff --git a/spec/active_relation/integration/scratch_spec.rb b/spec/active_relation/integration/scratch_spec.rb
index 6aa27bc1fe..a31c2ea9f6 100644
--- a/spec/active_relation/integration/scratch_spec.rb
+++ b/spec/active_relation/integration/scratch_spec.rb
@@ -82,7 +82,7 @@ describe 'ActiveRelation', 'A proposed refactoring to ActiveRecord, introducing
# MysqlAdapter from ActiveRecord is used to do the escaping.
end
- it 'generates the query for User.has_many :cameras :through => :photos' do
+ it 'generates the query for User.has_many :cameras, :through => :photos' do
# note, again, the compositionality of the operators:
user_cameras = photo_belongs_to_camera(user_has_many_photos(@user))
user_cameras.project(*@cameras.attributes).to_sql.should be_like("""
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("""