aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-03-12 22:41:30 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-03-12 22:41:30 -0700
commit2654c29bfdb2ccddfed8cceaaaba06e46892bdb9 (patch)
treecc7ab650792019aa4839036f1283f83801364537
parent46da601b2f5507325bba279d5c12ed88ce9e685e (diff)
downloadrails-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
-rw-r--r--README4
-rw-r--r--spec/active_relation/unit/predicates/binary_spec.rb2
-rw-r--r--spec/active_relation/unit/relations/join_spec.rb30
-rw-r--r--spec/active_relation/unit/relations/order_spec.rb2
-rw-r--r--spec/active_relation/unit/relations/projection_spec.rb4
-rw-r--r--spec/active_relation/unit/relations/range_spec.rb2
-rw-r--r--spec/active_relation/unit/relations/rename_spec.rb2
-rw-r--r--spec/active_relation/unit/relations/selection_spec.rb2
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