diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-12 22:41:30 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-12 22:41:30 -0700 |
commit | 2654c29bfdb2ccddfed8cceaaaba06e46892bdb9 (patch) | |
tree | cc7ab650792019aa4839036f1283f83801364537 /spec | |
parent | 46da601b2f5507325bba279d5c12ed88ce9e685e (diff) | |
download | rails-2654c29bfdb2ccddfed8cceaaaba06e46892bdb9.tar.gz rails-2654c29bfdb2ccddfed8cceaaaba06e46892bdb9.tar.bz2 rails-2654c29bfdb2ccddfed8cceaaaba06e46892bdb9.zip |
test coverage of #prefix_for on join.
- it delegates to the relation containing the attribute
- if the relation containing the attribute is an alias, it returns the alias
Diffstat (limited to 'spec')
7 files changed, 35 insertions, 9 deletions
diff --git a/spec/active_relation/unit/predicates/binary_spec.rb b/spec/active_relation/unit/predicates/binary_spec.rb index 677d8f3ab4..d552d8b501 100644 --- a/spec/active_relation/unit/predicates/binary_spec.rb +++ b/spec/active_relation/unit/predicates/binary_spec.rb @@ -34,7 +34,7 @@ module ActiveRelation end describe '#descend' do - it "distributes over the predicates and attributes" 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 diff --git a/spec/active_relation/unit/relations/join_spec.rb b/spec/active_relation/unit/relations/join_spec.rb index a424239c4b..fdc4a4cdf2 100644 --- a/spec/active_relation/unit/relations/join_spec.rb +++ b/spec/active_relation/unit/relations/join_spec.rb @@ -25,6 +25,13 @@ 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. \ @@ -33,8 +40,27 @@ module ActiveRelation end describe '#prefix_for' do - it 'needs a test' do - pending + describe 'when the joined relations are simple' do + it "returns the name of the relation containing the attribute" do + Join.new("INNER JOIN", @relation1, @relation2, @predicate).prefix_for(@relation1[:id]) \ + .should == @relation1.prefix_for(@relation1[:id]) + Join.new("INNER JOIN", @relation1, @relation2, @predicate).prefix_for(@relation2[:id]) \ + .should == @relation2.prefix_for(@relation2[:id]) + + end + end + + describe 'when one of the joined relations is an alias' do + before do + @aliased_relation = @relation1.as(:alias) + end + + it "returns the alias of the relation containing the attribute" do + Join.new("INNER JOIN", @aliased_relation, @relation2, @predicate).prefix_for(@aliased_relation[:id]) \ + .should == @aliased_relation.alias + Join.new("INNER JOIN", @aliased_relation, @relation2, @predicate).prefix_for(@relation2[:id]) \ + .should == @relation2.prefix_for(@relation2[:id]) + end end end diff --git a/spec/active_relation/unit/relations/order_spec.rb b/spec/active_relation/unit/relations/order_spec.rb index 032bd2b40f..6a9ce07024 100644 --- a/spec/active_relation/unit/relations/order_spec.rb +++ b/spec/active_relation/unit/relations/order_spec.rb @@ -15,7 +15,7 @@ module ActiveRelation end describe '#descend' do - it "distributes over the relation and attributes" 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 diff --git a/spec/active_relation/unit/relations/projection_spec.rb b/spec/active_relation/unit/relations/projection_spec.rb index 01a4d74bc6..9acfead8b8 100644 --- a/spec/active_relation/unit/relations/projection_spec.rb +++ b/spec/active_relation/unit/relations/projection_spec.rb @@ -31,14 +31,14 @@ module ActiveRelation end describe '#qualify' do - it "distributes over the relation and attributes" do + it "descends" do Projection.new(@relation, @attribute).qualify. \ should == Projection.new(@relation, @attribute).descend(&:qualify) end end describe '#descend' do - it "distributes over the relation and attributes" 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 diff --git a/spec/active_relation/unit/relations/range_spec.rb b/spec/active_relation/unit/relations/range_spec.rb index 7be2ca1b03..a0207c7342 100644 --- a/spec/active_relation/unit/relations/range_spec.rb +++ b/spec/active_relation/unit/relations/range_spec.rb @@ -14,7 +14,7 @@ module ActiveRelation end describe '#descend' do - it "distributes over the relation" do + it "distributes a block over the relation" do Range.new(@relation, @range).descend(&:qualify).should == Range.new(@relation.descend(&:qualify), @range) end end diff --git a/spec/active_relation/unit/relations/rename_spec.rb b/spec/active_relation/unit/relations/rename_spec.rb index c960f76736..9a63c4fc80 100644 --- a/spec/active_relation/unit/relations/rename_spec.rb +++ b/spec/active_relation/unit/relations/rename_spec.rb @@ -46,7 +46,7 @@ module ActiveRelation end describe '#descend' do - it "distributes over the relation and renames" 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 diff --git a/spec/active_relation/unit/relations/selection_spec.rb b/spec/active_relation/unit/relations/selection_spec.rb index d5e0c6a9f6..4bb3817bf5 100644 --- a/spec/active_relation/unit/relations/selection_spec.rb +++ b/spec/active_relation/unit/relations/selection_spec.rb @@ -23,7 +23,7 @@ module ActiveRelation end describe '#descend' do - it "distributes over the relation and predicates" do + it "distributes a block over the relation and predicates" do Selection.new(@relation, @predicate).descend(&:qualify). \ should == Selection.new(@relation.descend(&:qualify), @predicate.descend(&:qualify)) end |