diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-02-18 15:08:03 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-02-18 15:08:03 -0800 |
commit | 2a91d807538a4d39c5755fb83a5e9462e8056fa6 (patch) | |
tree | 93e7f9439c60231a71c8857478333dfdba7c5e2e | |
parent | b0eb6244122a5fd86beaaabb6381835aebb139d4 (diff) | |
download | rails-2a91d807538a4d39c5755fb83a5e9462e8056fa6.tar.gz rails-2a91d807538a4d39c5755fb83a5e9462e8056fa6.tar.bz2 rails-2a91d807538a4d39c5755fb83a5e9462e8056fa6.zip |
made descend public; added test coverage for it; tests for qualify are now in terms of descend
-rw-r--r-- | lib/active_relation/predicates.rb | 1 | ||||
-rw-r--r-- | lib/active_relation/relations/aggregation.rb | 1 | ||||
-rw-r--r-- | lib/active_relation/relations/join.rb | 8 | ||||
-rw-r--r-- | lib/active_relation/relations/order.rb | 1 | ||||
-rw-r--r-- | lib/active_relation/relations/projection.rb | 1 | ||||
-rw-r--r-- | lib/active_relation/relations/range.rb | 1 | ||||
-rw-r--r-- | lib/active_relation/relations/relation.rb | 1 | ||||
-rw-r--r-- | lib/active_relation/relations/rename.rb | 1 | ||||
-rw-r--r-- | lib/active_relation/relations/selection.rb | 9 | ||||
-rw-r--r-- | spec/active_relation/predicates/binary_spec.rb | 9 | ||||
-rw-r--r-- | spec/active_relation/relations/join_spec.rb | 3 | ||||
-rw-r--r-- | spec/active_relation/relations/order_spec.rb | 11 | ||||
-rw-r--r-- | spec/active_relation/relations/projection_spec.rb | 9 | ||||
-rw-r--r-- | spec/active_relation/relations/range_spec.rb | 10 | ||||
-rw-r--r-- | spec/active_relation/relations/rename_spec.rb | 13 | ||||
-rw-r--r-- | spec/active_relation/relations/selection_spec.rb | 11 |
16 files changed, 61 insertions, 29 deletions
diff --git a/lib/active_relation/predicates.rb b/lib/active_relation/predicates.rb index 67d910b9d1..c4f7b83512 100644 --- a/lib/active_relation/predicates.rb +++ b/lib/active_relation/predicates.rb @@ -28,7 +28,6 @@ module ActiveRelation "#{attribute.to_sql(strategy)} #{predicate_sql} #{operand.to_sql(strategy)}" end - protected def descend self.class.new(yield(attribute), yield(operand)) end diff --git a/lib/active_relation/relations/aggregation.rb b/lib/active_relation/relations/aggregation.rb index de21d2f383..d3a026820d 100644 --- a/lib/active_relation/relations/aggregation.rb +++ b/lib/active_relation/relations/aggregation.rb @@ -21,7 +21,6 @@ module ActiveRelation true end - protected def descend(&block) Aggregation.new(relation.descend(&block), :expressions => expressions.collect(&block), :groupings => groupings.collect(&block)) end diff --git a/lib/active_relation/relations/join.rb b/lib/active_relation/relations/join.rb index 6185293c8a..850a773ee5 100644 --- a/lib/active_relation/relations/join.rb +++ b/lib/active_relation/relations/join.rb @@ -31,6 +31,10 @@ module ActiveRelation end alias_method :aliased_prefix_for, :prefix_for + def descend(&block) + Join.new(join_sql, relation1.descend(&block), relation2.descend(&block), *predicates.collect(&block)) + end + protected def joins right_table_sql = relation2.aggregation?? relation2.to_sql(Sql::Aggregation.new) : relation2.send(:table_sql) @@ -48,9 +52,5 @@ module ActiveRelation def table_sql relation1.aggregation?? relation1.to_sql(Sql::Aggregation.new) : relation1.send(:table_sql) end - - def descend(&block) - Join.new(join_sql, relation1.descend(&block), relation2.descend(&block), *predicates.collect(&block)) - end end end
\ No newline at end of file diff --git a/lib/active_relation/relations/order.rb b/lib/active_relation/relations/order.rb index cee6278c80..e6395aecd7 100644 --- a/lib/active_relation/relations/order.rb +++ b/lib/active_relation/relations/order.rb @@ -11,7 +11,6 @@ module ActiveRelation orders == other.orders end - protected def descend(&block) Order.new(relation.descend(&block), *orders.collect(&block)) end diff --git a/lib/active_relation/relations/projection.rb b/lib/active_relation/relations/projection.rb index cd08a5aa54..c478ae145f 100644 --- a/lib/active_relation/relations/projection.rb +++ b/lib/active_relation/relations/projection.rb @@ -16,7 +16,6 @@ module ActiveRelation projections == other.projections end - protected def descend(&block) Projection.new(relation.descend(&block), *projections.collect(&block)) end diff --git a/lib/active_relation/relations/range.rb b/lib/active_relation/relations/range.rb index 14a86b8c65..fafdef5902 100644 --- a/lib/active_relation/relations/range.rb +++ b/lib/active_relation/relations/range.rb @@ -19,7 +19,6 @@ module ActiveRelation range.begin end - protected def descend(&block) Range.new(relation.descend(&block), range) end diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb index 7d33b42faf..e0ae882475 100644 --- a/lib/active_relation/relations/relation.rb +++ b/lib/active_relation/relations/relation.rb @@ -103,7 +103,6 @@ module ActiveRelation end alias_method :to_s, :to_sql - protected def descend yield self end diff --git a/lib/active_relation/relations/rename.rb b/lib/active_relation/relations/rename.rb index 1705d9ba8c..9a0e5552c7 100644 --- a/lib/active_relation/relations/rename.rb +++ b/lib/active_relation/relations/rename.rb @@ -18,7 +18,6 @@ module ActiveRelation relation.attributes.collect(&method(:baptize)) end - protected def descend(&block) Rename.new(relation.descend(&block), yield(attribute) => pseudonym) end diff --git a/lib/active_relation/relations/selection.rb b/lib/active_relation/relations/selection.rb index f8cd235419..e7a91f7572 100644 --- a/lib/active_relation/relations/selection.rb +++ b/lib/active_relation/relations/selection.rb @@ -13,14 +13,13 @@ module ActiveRelation predicate == other.predicate end - protected - def selects - relation.send(:selects) + [predicate] - end - def descend(&block) Selection.new(relation.descend(&block), yield(predicate)) end + protected + def selects + relation.send(:selects) + [predicate] + end end end
\ No newline at end of file diff --git a/spec/active_relation/predicates/binary_spec.rb b/spec/active_relation/predicates/binary_spec.rb index 89a40d2bf3..4f37a6aa7e 100644 --- a/spec/active_relation/predicates/binary_spec.rb +++ b/spec/active_relation/predicates/binary_spec.rb @@ -27,8 +27,15 @@ module ActiveRelation 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 over the predicates and attributes" do - ConcreteBinary.new(@attribute1, @attribute2).qualify. \ + ConcreteBinary.new(@attribute1, @attribute2).descend(&:qualify). \ should == ConcreteBinary.new(@attribute1.qualify, @attribute2.qualify) end end diff --git a/spec/active_relation/relations/join_spec.rb b/spec/active_relation/relations/join_spec.rb index b60238fa7e..77c6baeac4 100644 --- a/spec/active_relation/relations/join_spec.rb +++ b/spec/active_relation/relations/join_spec.rb @@ -25,14 +25,13 @@ module ActiveRelation end end - describe '#qualify' do + 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 it 'needs a test' do pending diff --git a/spec/active_relation/relations/order_spec.rb b/spec/active_relation/relations/order_spec.rb index 12b9761431..32a54e72fa 100644 --- a/spec/active_relation/relations/order_spec.rb +++ b/spec/active_relation/relations/order_spec.rb @@ -8,9 +8,16 @@ module ActiveRelation end describe '#qualify' do - it "distributes over the relation and attributes" do + it "descends" do Order.new(@relation, @attribute).qualify. \ - should == Order.new(@relation.qualify, @attribute.qualify) + should == Order.new(@relation, @attribute).descend(&:qualify) + end + end + + describe '#descend' do + it "distributes over the relation and attributes" do + Order.new(@relation, @attribute).descend(&:qualify). \ + should == Order.new(@relation.descend(&:qualify), @attribute.qualify) end end diff --git a/spec/active_relation/relations/projection_spec.rb b/spec/active_relation/relations/projection_spec.rb index 2bc4ed1d6e..9f6b6797ce 100644 --- a/spec/active_relation/relations/projection_spec.rb +++ b/spec/active_relation/relations/projection_spec.rb @@ -33,7 +33,14 @@ module ActiveRelation describe '#qualify' do it "distributes over the relation and attributes" do Projection.new(@relation, @attribute).qualify. \ - should == Projection.new(@relation.qualify, @attribute.qualify) + should == Projection.new(@relation, @attribute).descend(&:qualify) + end + end + + describe '#descend' do + it "distributes over the relation and attributes" do + Projection.new(@relation, @attribute).descend(&:qualify). \ + should == Projection.new(@relation.descend(&:qualify), @attribute.qualify) end end diff --git a/spec/active_relation/relations/range_spec.rb b/spec/active_relation/relations/range_spec.rb index a2f84c2e88..f27b6106e8 100644 --- a/spec/active_relation/relations/range_spec.rb +++ b/spec/active_relation/relations/range_spec.rb @@ -8,11 +8,17 @@ module ActiveRelation end describe '#qualify' do + it "descends" do + Range.new(@relation, @range).qualify.should == Range.new(@relation, @range).descend(&:qualify) + end + end + + describe '#descend' do it "distributes over the relation" do - Range.new(@relation, @range).qualify.should == Range.new(@relation.qualify, @range) + Range.new(@relation, @range).descend(&:qualify).should == Range.new(@relation.descend(&:qualify), @range) end end - + describe '#to_sql' do it "manufactures sql with limit and offset" do range_size = @range.last - @range.first + 1 diff --git a/spec/active_relation/relations/rename_spec.rb b/spec/active_relation/relations/rename_spec.rb index deb538615b..6c6bd450f5 100644 --- a/spec/active_relation/relations/rename_spec.rb +++ b/spec/active_relation/relations/rename_spec.rb @@ -37,11 +37,18 @@ module ActiveRelation @renamed_relation.should have(@relation.attributes.size).attributes end end - + describe '#qualify' do - it "distributes over the relation and renames" do + it "descends" do Rename.new(@relation, @relation[:id] => :schmid).qualify. \ - should == Rename.new(@relation.qualify, @relation[:id].qualify => :schmid) + should == Rename.new(@relation, @relation[:id] => :schmid).descend(&:qualify) + end + end + + describe '#descend' do + it "distributes 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 diff --git a/spec/active_relation/relations/selection_spec.rb b/spec/active_relation/relations/selection_spec.rb index 66ad54de19..b6db6bfd4a 100644 --- a/spec/active_relation/relations/selection_spec.rb +++ b/spec/active_relation/relations/selection_spec.rb @@ -16,9 +16,16 @@ module ActiveRelation end describe '#qualify' do - it "distributes over the relation and predicates" do + it "descends" do Selection.new(@relation, @predicate).qualify. \ - should == Selection.new(@relation.qualify, @predicate.qualify) + should == Selection.new(@relation, @predicate).descend(&:qualify) + end + end + + describe '#descend' do + it "distributes over the relation and predicates" do + Selection.new(@relation, @predicate).descend(&:qualify). \ + should == Selection.new(@relation.descend(&:qualify), @predicate.descend(&:qualify)) end end |