From 2654c29bfdb2ccddfed8cceaaaba06e46892bdb9 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Wed, 12 Mar 2008 22:41:30 -0700 Subject: [PATCH] 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 --- README | 4 +-- .../unit/predicates/binary_spec.rb | 2 +- .../unit/relations/join_spec.rb | 30 +++++++++++++++++-- .../unit/relations/order_spec.rb | 2 +- .../unit/relations/projection_spec.rb | 4 +-- .../unit/relations/range_spec.rb | 2 +- .../unit/relations/rename_spec.rb | 2 +- .../unit/relations/selection_spec.rb | 2 +- 8 files changed, 37 insertions(+), 11 deletions(-) diff --git a/README b/README index d60a4ec0bb..54a698c768 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ == Abstract == -ActiveRelation is a Relational Algebra for Ruby. It simplifies the generation of both the simplest and the most complex of SQL queries and it transparently adapts to various RDBMS systems. It is intended to be a framework framework; that is, you can build your own ORM with it, focusing on innovative object and collection modeling as opposed to database compatibility and query generation. +ActiveRelation is a Relational Algebra for Ruby. It 1) simplifies the generation of both the simplest and the most complex of SQL queries and it 2) transparently adapts to various RDBMS systems. It is intended to be a framework framework; that is, you can build your own ORM with it, focusing on innovative object and collection modeling as opposed to database compatibility and query generation. == A Gentle Introduction == @@ -58,7 +58,7 @@ The best property of the Relational is compositionality, or closure under all op .select(users[:name].equals('amy')) \ .project(users[:id]) \ # => SELECT users.id FROM users WHERE users.name = 'amy' -s + == Contributions == 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