From 1b8f72746b38ce1e08b5fab48f3251eb09f2cba0 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Sat, 12 Apr 2008 16:43:48 -0700 Subject: - removed #qualify and #descend helper - qualify seems no longer neccessary since everything is fully qualified - finished pending specs --- .../active_relation/unit/predicates/binary_spec.rb | 14 --------- .../unit/primitives/attribute_spec.rb | 33 +++++++++++----------- spec/active_relation/unit/relations/join_spec.rb | 14 --------- spec/active_relation/unit/relations/order_spec.rb | 14 --------- .../unit/relations/projection_spec.rb | 14 --------- .../unit/relations/relation_spec.rb | 9 ++---- spec/active_relation/unit/relations/rename_spec.rb | 14 --------- .../unit/relations/selection_spec.rb | 20 +------------ spec/active_relation/unit/relations/skip_spec.rb | 12 -------- spec/active_relation/unit/relations/table_spec.rb | 11 ++------ spec/active_relation/unit/relations/take_spec.rb | 18 ++---------- 11 files changed, 25 insertions(+), 148 deletions(-) (limited to 'spec/active_relation') diff --git a/spec/active_relation/unit/predicates/binary_spec.rb b/spec/active_relation/unit/predicates/binary_spec.rb index 5dd5e5599a..56c568b078 100644 --- a/spec/active_relation/unit/predicates/binary_spec.rb +++ b/spec/active_relation/unit/predicates/binary_spec.rb @@ -57,20 +57,6 @@ module ActiveRelation end end - describe '#qualify' do - it "descends" do - ConcreteBinary.new(@attribute1, @attribute2).qualify \ - .should == ConcreteBinary.new(@attribute1, @attribute2).descend(&:qualify) - end - end - - describe '#descend' do - it "distributes a block over the predicates and attributes" do - ConcreteBinary.new(@attribute1, @attribute2).descend(&:qualify). \ - should == ConcreteBinary.new(@attribute1.qualify, @attribute2.qualify) - end - end - describe '#bind' do before do @another_relation = Table.new(:photos) diff --git a/spec/active_relation/unit/primitives/attribute_spec.rb b/spec/active_relation/unit/primitives/attribute_spec.rb index fbbcbaef37..08ed6d3621 100644 --- a/spec/active_relation/unit/primitives/attribute_spec.rb +++ b/spec/active_relation/unit/primitives/attribute_spec.rb @@ -21,16 +21,10 @@ module ActiveRelation end it "returns self if the substituting to the same relation" do - @attribute.should == @attribute + @attribute.bind(@relation).should == @attribute end end - describe '#qualify' do - it "manufactures an attribute aliased with that attribute's qualified name" do - @attribute.qualify.should == Attribute.new(@attribute.relation, @attribute.name, :alias => @attribute.qualified_name, :ancestor => @attribute) - end - end - describe '#to_attribute' do it "returns self" do @attribute.to_attribute.should == @attribute @@ -40,16 +34,13 @@ module ActiveRelation describe '#column' do it "returns the corresponding column in the relation" do - pending "damn mock based tests are too easy" - stub(@relation).column_for(@attribute) { 'bruisers' } - @attribute.column.should == 'bruisers' + @attribute.column.should == @relation.column_for(@attribute) end end describe '#qualified_name' do it "manufactures an attribute name prefixed with the relation's name" do - stub(@relation).prefix_for(anything) { 'bruisers' } - Attribute.new(@relation, :id).qualified_name.should == 'bruisers.id' + @attribute.qualified_name.should == "#{@relation.prefix_for(@attribute)}.id" end end @@ -80,13 +71,21 @@ module ActiveRelation end describe '#to_sql' do - it "" do - pending "this test is not sufficiently resilient" + describe 'for a simple attribute' do + it "manufactures sql with an alias" do + @attribute.to_sql.should be_like("`users`.`id`") + end end - it "manufactures sql with an alias" do - stub(@relation).prefix_for(anything) { 'bruisers' } - Attribute.new(@relation, :name, :alias => :alias).to_sql.should be_like("`bruisers`.`name`") + describe 'for an attribute in a join relation where the source relation is aliased' do + before do + another_relation = Table.new(:photos) + @join_with_alias = @relation.as(:alias).join(another_relation).on(@relation[:id].eq(another_relation[:user_id])) + end + + it "manufactures sql with an alias" do + @join_with_alias[@attribute].to_sql.should be_like("`alias`.`id`") + end end end diff --git a/spec/active_relation/unit/relations/join_spec.rb b/spec/active_relation/unit/relations/join_spec.rb index 423e513be4..73dd67bec8 100644 --- a/spec/active_relation/unit/relations/join_spec.rb +++ b/spec/active_relation/unit/relations/join_spec.rb @@ -32,20 +32,6 @@ module ActiveRelation end end - describe '#qualify' do - it 'descends' do - Join.new("INNER JOIN", @relation1, @relation2, @predicate).qualify. \ - should == Join.new("INNER JOIN", @relation1, @relation2, @predicate).descend(&:qualify) - end - end - - describe '#descend' 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 '#prefix_for' do describe 'when the joined relations are simple' do it "returns the name of the relation containing the attribute" do diff --git a/spec/active_relation/unit/relations/order_spec.rb b/spec/active_relation/unit/relations/order_spec.rb index db322fe00b..e8a2f4c227 100644 --- a/spec/active_relation/unit/relations/order_spec.rb +++ b/spec/active_relation/unit/relations/order_spec.rb @@ -18,20 +18,6 @@ module ActiveRelation end end - describe '#qualify' do - it "descends" do - Order.new(@relation, @attribute).qualify. \ - should == Order.new(@relation, @attribute).descend(&:qualify) - end - end - - describe '#descend' do - it "distributes a block over the relation and attributes" do - Order.new(@relation, @attribute).descend(&:qualify). \ - should == Order.new(@relation.descend(&:qualify), @attribute.qualify) - end - end - describe '#to_sql' do describe "when given an attribute" do it "manufactures sql with an order clause populated by the attribute" do diff --git a/spec/active_relation/unit/relations/projection_spec.rb b/spec/active_relation/unit/relations/projection_spec.rb index f58564840b..529998a8d4 100644 --- a/spec/active_relation/unit/relations/projection_spec.rb +++ b/spec/active_relation/unit/relations/projection_spec.rb @@ -30,20 +30,6 @@ module ActiveRelation end end - describe '#qualify' do - it "descends" do - Projection.new(@relation, @attribute).qualify. \ - should == Projection.new(@relation, @attribute).descend(&:qualify) - end - end - - describe '#descend' do - it "distributes a block over the relation and attributes" do - Projection.new(@relation, @attribute).descend(&:qualify). \ - should == Projection.new(@relation.descend(&:qualify), @attribute.qualify) - end - end - describe '#to_sql' do describe 'when given an attribute' do it "manufactures sql with a limited select clause" do diff --git a/spec/active_relation/unit/relations/relation_spec.rb b/spec/active_relation/unit/relations/relation_spec.rb index 2a04276aeb..fa66352c91 100644 --- a/spec/active_relation/unit/relations/relation_spec.rb +++ b/spec/active_relation/unit/relations/relation_spec.rb @@ -174,12 +174,9 @@ module ActiveRelation end describe Relation::Enumerable do - it "is enumerable" do - pending "I don't like this mock-based test" - data = [1,2,3] - mock.instance_of(Session).read(anything) { data } - @relation.collect.should == data - @relation.first.should == data.first + it "implements enumerable" do + @relation.collect.should == @relation.session.read(@relation) + @relation.first.should == @relation.session.read(@relation).first end end end diff --git a/spec/active_relation/unit/relations/rename_spec.rb b/spec/active_relation/unit/relations/rename_spec.rb index 9a63c4fc80..192c819848 100644 --- a/spec/active_relation/unit/relations/rename_spec.rb +++ b/spec/active_relation/unit/relations/rename_spec.rb @@ -38,20 +38,6 @@ module ActiveRelation end end - describe '#qualify' do - it "descends" do - Rename.new(@relation, @relation[:id] => :schmid).qualify. \ - should == Rename.new(@relation, @relation[:id] => :schmid).descend(&:qualify) - end - end - - describe '#descend' do - it "distributes a block over the relation and renames" do - Rename.new(@relation, @relation[:id] => :schmid).descend(&:qualify). \ - should == Rename.new(@relation.descend(&:qualify), @relation[:id].qualify => :schmid) - end - end - describe '#to_sql' do it 'manufactures sql renaming the attribute' do Rename.new(@relation, @relation[:id] => :schmid).to_sql.should be_like(" diff --git a/spec/active_relation/unit/relations/selection_spec.rb b/spec/active_relation/unit/relations/selection_spec.rb index 20833de58d..d87e075f98 100644 --- a/spec/active_relation/unit/relations/selection_spec.rb +++ b/spec/active_relation/unit/relations/selection_spec.rb @@ -17,25 +17,7 @@ module ActiveRelation should == Selection.new(Selection.new(@relation, @another_predicate), @predicate) end end - - describe '#qualify' do - it "descends" do - Selection.new(@relation, @predicate).qualify. \ - should == Selection.new(@relation, @predicate).descend(&:qualify) - end - end - - describe '#descend' do - before do - @selection = Selection.new(@relation, @predicate) - end - - it "distributes a block over the relation and predicates" do - @selection.descend(&:qualify). \ - should == Selection.new(@selection.relation.descend(&:qualify), @selection.predicate.qualify) - end - end - + describe '#to_sql' do describe 'when given a predicate' do it "manufactures sql with where clause conditions" do diff --git a/spec/active_relation/unit/relations/skip_spec.rb b/spec/active_relation/unit/relations/skip_spec.rb index d50ef715ee..219bfdd80e 100644 --- a/spec/active_relation/unit/relations/skip_spec.rb +++ b/spec/active_relation/unit/relations/skip_spec.rb @@ -7,18 +7,6 @@ module ActiveRelation @skipped = 4 end - describe '#qualify' do - it "descends" do - Skip.new(@relation, @skipped).qualify.should == Skip.new(@relation, @skipped).descend(&:qualify) - end - end - - describe '#descend' do - it "distributes a block over the relation" do - Skip.new(@relation, @skipped).descend(&:qualify).should == Skip.new(@relation.descend(&:qualify), @skipped) - end - end - describe '#to_sql' do it "manufactures sql with limit and offset" do Skip.new(@relation, @skipped).to_s.should be_like(" diff --git a/spec/active_relation/unit/relations/table_spec.rb b/spec/active_relation/unit/relations/table_spec.rb index 6286ea9de1..2751d9cb63 100644 --- a/spec/active_relation/unit/relations/table_spec.rb +++ b/spec/active_relation/unit/relations/table_spec.rb @@ -46,8 +46,8 @@ module ActiveRelation end describe '#column_for' do - it "" do - @relation[:id].column.should == @relation.columns.detect { |c| c.name == 'id' } + it "returns the column corresponding to the attribute" do + @relation.column_for(@relation[:id]).should == @relation.columns.detect { |c| c.name == 'id' } end end @@ -68,19 +68,12 @@ module ActiveRelation describe '#reset' do it "reloads columns from the database" do - pending lambda { stub(@relation.engine).columns { [] } }.should_not change { @relation.attributes } lambda { @relation.reset }.should change { @relation.attributes } end end end - describe '#qualify' do - it 'manufactures a rename relation with all attribute names qualified' do - @relation.qualify.should == Rename.new(@relation, @relation[:name] => 'users.name', @relation[:id] => 'users.id') - end - end - describe 'hashing' do it "implements hash equality" do Table.new(:users).should hash_the_same_as(Table.new(:users)) diff --git a/spec/active_relation/unit/relations/take_spec.rb b/spec/active_relation/unit/relations/take_spec.rb index beaa9e2f8c..8c13732258 100644 --- a/spec/active_relation/unit/relations/take_spec.rb +++ b/spec/active_relation/unit/relations/take_spec.rb @@ -4,27 +4,15 @@ module ActiveRelation describe Take do before do @relation = Table.new(:users) - @takene = 4 + @taken = 4 end - describe '#qualify' do - it "descends" do - Take.new(@relation, @takene).qualify.should == Take.new(@relation, @takene).descend(&:qualify) - end - end - - describe '#descend' do - it "distributes a block over the relation" do - Take.new(@relation, @takene).descend(&:qualify).should == Take.new(@relation.descend(&:qualify), @takene) - end - end - describe '#to_sql' do it "manufactures sql with limit and offset" do - Take.new(@relation, @takene).to_s.should be_like(" + Take.new(@relation, @taken).to_s.should be_like(" SELECT `users`.`id`, `users`.`name` FROM `users` - LIMIT #{@takene} + LIMIT #{@taken} ") end end -- cgit v1.2.3