aboutsummaryrefslogtreecommitdiffstats
path: root/spec/relations
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-05 15:24:46 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-05 15:24:46 -0800
commitd7b89d957dbceb4eeceb0b1d381474a4de70a14d (patch)
treeb5d84358426ad29410451eec87d7cc77ca39ad8c /spec/relations
parent346d9c6bde5ae0a0c918b4e0b25d79aa2760234a (diff)
downloadrails-d7b89d957dbceb4eeceb0b1d381474a4de70a14d.tar.gz
rails-d7b89d957dbceb4eeceb0b1d381474a4de70a14d.tar.bz2
rails-d7b89d957dbceb4eeceb0b1d381474a4de70a14d.zip
qualified naming
Diffstat (limited to 'spec/relations')
-rw-r--r--spec/relations/attribute_spec.rb34
-rw-r--r--spec/relations/order_relation_spec.rb7
-rw-r--r--spec/relations/projection_relation_spec.rb7
-rw-r--r--spec/relations/range_relation_spec.rb6
-rw-r--r--spec/relations/relation_spec.rb20
-rw-r--r--spec/relations/rename_relation_spec.rb68
-rw-r--r--spec/relations/selection_relation_spec.rb7
-rw-r--r--spec/relations/table_relation_spec.rb14
8 files changed, 143 insertions, 20 deletions
diff --git a/spec/relations/attribute_spec.rb b/spec/relations/attribute_spec.rb
index 7015fd2542..4887be38d2 100644
--- a/spec/relations/attribute_spec.rb
+++ b/spec/relations/attribute_spec.rb
@@ -6,24 +6,41 @@ describe Attribute do
@relation2 = TableRelation.new(:bar)
end
- describe 'aliaz' do
+ describe '#aliazz' do
it "manufactures an aliased attributed" do
pending
end
+
+ it "should be renamed to #alias!" do
+ pending
+ @relation1.alias
+ end
+ end
+
+ describe '#qualified_name' do
+ it "manufactures an attribute name prefixed with the relation's name" do
+ @relation1[:id].qualified_name.should == 'foo.id'
+ end
+ end
+
+ describe '#qualify' do
+ it "manufactures an attribute aliased with that attributes qualified name" do
+ @relation1[:id].qualify == @relation1[:id].qualify
+ end
end
describe '#eql?' do
it "obtains if the relation and attribute name are identical" do
- Attribute.new(@relation1, :attribute_name).should be_eql(Attribute.new(@relation1, :attribute_name))
- Attribute.new(@relation1, :attribute_name).should_not be_eql(Attribute.new(@relation1, :another_attribute_name))
- Attribute.new(@relation1, :attribute_name).should_not be_eql(Attribute.new(@relation2, :attribute_name))
+ Attribute.new(@relation1, :name).should be_eql(Attribute.new(@relation1, :name))
+ Attribute.new(@relation1, :name).should_not be_eql(Attribute.new(@relation1, :another_name))
+ Attribute.new(@relation1, :name).should_not be_eql(Attribute.new(@relation2, :name))
end
end
describe 'predications' do
before do
- @attribute1 = Attribute.new(@relation1, :attribute_name)
- @attribute2 = Attribute.new(@relation2, :attribute_name)
+ @attribute1 = Attribute.new(@relation1, :name)
+ @attribute2 = Attribute.new(@relation2, :name)
end
describe '==' do
@@ -63,11 +80,10 @@ describe Attribute do
end
end
-
describe '#to_sql' do
it "manufactures a column" do
- Attribute.new(@relation1, :attribute_name, :alias).to_sql.should == SelectsBuilder.new do
- column :foo, :attribute_name, :alias
+ Attribute.new(@relation1, :name, :alias).to_sql.should == SelectsBuilder.new do
+ column :foo, :name, :alias
end
end
end
diff --git a/spec/relations/order_relation_spec.rb b/spec/relations/order_relation_spec.rb
index d0654bd8da..62275ff0ac 100644
--- a/spec/relations/order_relation_spec.rb
+++ b/spec/relations/order_relation_spec.rb
@@ -16,6 +16,13 @@ describe OrderRelation do
end
end
+ describe '#qualify' do
+ it "manufactures an order relation with qualified attributes and qualified relation" do
+ OrderRelation.new(@relation1, @attribute1).qualify. \
+ should == OrderRelation.new(@relation1.qualify, @attribute1.qualify)
+ end
+ end
+
describe '#to_sql' do
it "manufactures sql with an order clause" do
OrderRelation.new(@relation1, @attribute1).to_sql.to_s.should == SelectBuilder.new do
diff --git a/spec/relations/projection_relation_spec.rb b/spec/relations/projection_relation_spec.rb
index 47386f966d..eb74b5cedf 100644
--- a/spec/relations/projection_relation_spec.rb
+++ b/spec/relations/projection_relation_spec.rb
@@ -16,6 +16,13 @@ describe ProjectionRelation do
end
end
+ describe '#qualify' do
+ it "manufactures a projection relation with qualified attributes and qualified relation" do
+ ProjectionRelation.new(@relation1, @attribute1).qualify. \
+ should == ProjectionRelation.new(@relation1.qualify, @attribute1.qualify)
+ end
+ end
+
describe '#to_sql' do
it "manufactures sql with a limited select clause" do
ProjectionRelation.new(@relation1, @attribute1).to_sql.to_s.should == SelectBuilder.new do
diff --git a/spec/relations/range_relation_spec.rb b/spec/relations/range_relation_spec.rb
index ea3901e3fd..261afcaf8e 100644
--- a/spec/relations/range_relation_spec.rb
+++ b/spec/relations/range_relation_spec.rb
@@ -16,6 +16,12 @@ describe RangeRelation do
end
end
+ describe '#qualify' do
+ it "manufactures a range relation with a qualified relation and a qualified range" do
+ pending
+ end
+ end
+
describe '#to_sql' do
it "manufactures sql with limit and offset" do
range_size = @range2.last - @range2.first + 1
diff --git a/spec/relations/relation_spec.rb b/spec/relations/relation_spec.rb
index 5cef7d7b3d..d029827f21 100644
--- a/spec/relations/relation_spec.rb
+++ b/spec/relations/relation_spec.rb
@@ -8,21 +8,21 @@ describe Relation do
@attribute2 = Attribute.new(@relation1, :name)
end
- describe Relation, 'joins' do
- describe Relation, '<=>' do
+ describe 'joins' do
+ describe '<=>' do
it "manufactures an inner join operation between those two relations" do
(@relation1 <=> @relation2).should == InnerJoinOperation.new(@relation1, @relation2)
end
end
- describe Relation, '<<' do
+ describe '<<' do
it "manufactures a left outer join operation between those two relations" do
(@relation1 << @relation2).should == LeftOuterJoinOperation.new(@relation1, @relation2)
end
end
end
- describe Relation, '[]' do
+ describe '[]' do
it "manufactures an attribute when given a symbol" do
@relation1[:id].should be_eql(Attribute.new(@relation1, :id))
end
@@ -32,13 +32,13 @@ describe Relation do
end
end
- describe Relation, '#include?' do
+ describe '#include?' do
it "manufactures an inclusion predicate" do
@relation1.include?(@attribute1).should == RelationInclusionPredicate.new(@attribute1, @relation1)
end
end
- describe Relation, '#project' do
+ describe '#project' do
it "collapses identical projections" do
pending
end
@@ -48,13 +48,13 @@ describe Relation do
end
end
- describe Relation, '#rename' do
+ describe '#rename' do
it "manufactures a rename relation" do
- @relation1.rename(@attribute1, :foo).should == RenameRelation.new(@relation1, @attribute1, :foo)
+ @relation1.rename(@attribute1, :foo).should == RenameRelation.new(@relation1, @attribute1 => :foo)
end
end
- describe Relation, '#select' do
+ describe '#select' do
before do
@predicate = EqualityPredicate.new(@attribute1, @attribute2)
end
@@ -64,7 +64,7 @@ describe Relation do
end
end
- describe Relation, 'order' do
+ describe 'order' do
it "manufactures an order relation" do
@relation1.order(@attribute1, @attribute2).should == OrderRelation.new(@relation1, @attribute1, @attribute2)
end
diff --git a/spec/relations/rename_relation_spec.rb b/spec/relations/rename_relation_spec.rb
new file mode 100644
index 0000000000..e7792d146a
--- /dev/null
+++ b/spec/relations/rename_relation_spec.rb
@@ -0,0 +1,68 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe RenameRelation do
+ before do
+ @relation = TableRelation.new(:foo)
+ @renamed_relation = RenameRelation.new(@relation, @relation[:id] => :schmid)
+ end
+
+ describe '#initialize' do
+ it "manufactures nested rename relations if multiple renames are provided" do
+ RenameRelation.new(@relation, @relation[:id] => :humpty, @relation[:name] => :dumpty). \
+ should == RenameRelation.new(RenameRelation.new(@relation, @relation[:id] => :humpty), @relation[:name] => :dumpty)
+ end
+
+ it "make this test less brittle wrt/ hash order" do
+ pending
+ end
+
+ it "raises an exception if the alias provided is already used" do
+ pending
+ end
+ end
+
+ describe '==' do
+ it "obtains if the relation, attribute, and alias are identical" do
+ pending
+ end
+ end
+
+ describe '#attributes' do
+ it "manufactures a list of attributes with the renamed attribute aliased" do
+ RenameRelation.new(@relation, @relation[:id] => :schmid).attributes.should ==
+ (@relation.attributes - [@relation[:id]]) + [@relation[:id].aliazz(:schmid)]
+ end
+ end
+
+ describe '[]' do
+ it 'indexes attributes by alias' do
+ @renamed_relation[:id].should be_nil
+ @renamed_relation[:schmid].should == @relation[:id]
+ end
+ end
+
+ describe '#schmattribute' do
+ it "should be renamed" do
+ pending
+ end
+ end
+
+ describe '#qualify' do
+ it "manufactures a rename relation with an identical attribute and alias, but with a qualified relation" do
+ RenameRelation.new(@relation, @relation[:id] => :schmid).qualify. \
+ should == RenameRelation.new(@relation.qualify, @relation[:id].qualify => :schmid)
+ end
+ end
+
+ describe '#to_sql' do
+ it 'manufactures sql aliasing the attribute' do
+ @renamed_relation.to_sql.to_s.should == SelectBuilder.new do
+ select do
+ column :foo, :name
+ column :foo, :id, :schmid
+ end
+ from :foo
+ end.to_s
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/relations/selection_relation_spec.rb b/spec/relations/selection_relation_spec.rb
index 1a7f9e6659..395a3f7693 100644
--- a/spec/relations/selection_relation_spec.rb
+++ b/spec/relations/selection_relation_spec.rb
@@ -26,6 +26,13 @@ describe SelectionRelation do
end
end
+ describe '#qualify' do
+ it "manufactures a selection relation with qualified predicates and qualified relation" do
+ SelectionRelation.new(@relation1, @predicate1).qualify. \
+ should == SelectionRelation.new(@relation1.qualify, @predicate1.qualify)
+ end
+ end
+
describe '#to_sql' do
it "manufactures sql with where clause conditions" do
SelectionRelation.new(@relation1, @predicate1).to_sql.to_s.should == SelectBuilder.new do
diff --git a/spec/relations/table_relation_spec.rb b/spec/relations/table_relation_spec.rb
index dec8bba6b1..0380372344 100644
--- a/spec/relations/table_relation_spec.rb
+++ b/spec/relations/table_relation_spec.rb
@@ -1,9 +1,13 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
describe TableRelation do
+ before do
+ @relation = TableRelation.new(:users)
+ end
+
describe '#to_sql' do
it "returns a simple SELECT query" do
- TableRelation.new(:users).to_sql.should == SelectBuilder.new do |s|
+ @relation.to_sql.should == SelectBuilder.new do |s|
select do
column :users, :name
column :users, :id
@@ -18,4 +22,12 @@ describe TableRelation do
pending
end
end
+
+ describe '#qualify' do
+ it 'manufactures a rename relation with all attribute names qualified' do
+ @relation.qualify.should == RenameRelation.new(
+ RenameRelation.new(@relation, @relation[:id] => 'users.id'), @relation[:name] => 'users.name'
+ )
+ end
+ end
end \ No newline at end of file