1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
Nick Kallen 2008-03-12 22:41:30 -07:00
parent 46da601b2f
commit 2654c29bfd
8 changed files with 37 additions and 11 deletions

4
README
View file

@ -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 ==

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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