aboutsummaryrefslogtreecommitdiffstats
path: root/spec/relations
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-07 18:37:20 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-07 18:37:20 -0800
commit311f5f8eb588d4cde051762ace87a61425300bec (patch)
tree5e087ddd6257ad793c225555a6e48ad17bbdde70 /spec/relations
parentd43a4e9fc1316fc9eb8ff087c52c7ca7a475c041 (diff)
downloadrails-311f5f8eb588d4cde051762ace87a61425300bec.tar.gz
rails-311f5f8eb588d4cde051762ace87a61425300bec.tar.bz2
rails-311f5f8eb588d4cde051762ace87a61425300bec.zip
minor
Diffstat (limited to 'spec/relations')
-rw-r--r--spec/relations/attribute_spec.rb90
-rw-r--r--spec/relations/join_operation_spec.rb35
-rw-r--r--spec/relations/join_relation_spec.rb59
-rw-r--r--spec/relations/order_relation_spec.rb41
-rw-r--r--spec/relations/projection_relation_spec.rb36
-rw-r--r--spec/relations/range_relation_spec.rb41
-rw-r--r--spec/relations/relation_spec.rb72
-rw-r--r--spec/relations/rename_relation_spec.rb64
-rw-r--r--spec/relations/selection_relation_spec.rb53
-rw-r--r--spec/relations/table_relation_spec.rb33
10 files changed, 0 insertions, 524 deletions
diff --git a/spec/relations/attribute_spec.rb b/spec/relations/attribute_spec.rb
deleted file mode 100644
index 4887be38d2..0000000000
--- a/spec/relations/attribute_spec.rb
+++ /dev/null
@@ -1,90 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe Attribute do
- before do
- @relation1 = TableRelation.new(:foo)
- @relation2 = TableRelation.new(:bar)
- end
-
- 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, :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, :name)
- @attribute2 = Attribute.new(@relation2, :name)
- end
-
- describe '==' do
- it "manufactures an equality predicate" do
- (@attribute1 == @attribute2).should == EqualityPredicate.new(@attribute1, @attribute2)
- end
- end
-
- describe '<' do
- it "manufactures a less-than predicate" do
- (@attribute1 < @attribute2).should == LessThanPredicate.new(@attribute1, @attribute2)
- end
- end
-
- describe '<=' do
- it "manufactures a less-than or equal-to predicate" do
- (@attribute1 <= @attribute2).should == LessThanOrEqualToPredicate.new(@attribute1, @attribute2)
- end
- end
-
- describe '>' do
- it "manufactures a greater-than predicate" do
- (@attribute1 > @attribute2).should == GreaterThanPredicate.new(@attribute1, @attribute2)
- end
- end
-
- describe '>=' do
- it "manufactures a greater-than or equal to predicate" do
- (@attribute1 >= @attribute2).should == GreaterThanOrEqualToPredicate.new(@attribute1, @attribute2)
- end
- end
-
- describe '=~' do
- it "manufactures a match predicate" do
- (@attribute1 =~ /.*/).should == MatchPredicate.new(@attribute1, @attribute2)
- end
- end
- end
-
- describe '#to_sql' do
- it "manufactures a column" do
- Attribute.new(@relation1, :name, :alias).to_sql.should == SelectsBuilder.new do
- column :foo, :name, :alias
- end
- end
- end
-end
diff --git a/spec/relations/join_operation_spec.rb b/spec/relations/join_operation_spec.rb
deleted file mode 100644
index db30198f6e..0000000000
--- a/spec/relations/join_operation_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe 'between two relations' do
- before do
- @relation1 = TableRelation.new(:foo)
- @relation2 = TableRelation.new(:bar)
- end
-
- describe '==' do
- it "obtains if the relations of both joins are identical" do
- JoinOperation.new(@relation1, @relation2).should == JoinOperation.new(@relation1, @relation2)
- JoinOperation.new(@relation1, @relation2).should_not == JoinOperation.new(@relation1, @relation1)
- end
-
- it "is commutative on the relations" do
- JoinOperation.new(@relation1, @relation2).should == JoinOperation.new(@relation2, @relation1)
- end
- end
-
- describe 'on' do
- before do
- @predicate = Predicate.new
- @join_operation = JoinOperation.new(@relation1, @relation2)
- class << @join_operation
- def relation_class
- JoinRelation
- end
- end
- end
-
- it "manufactures a join relation of the appropriate type" do
- @join_operation.on(@predicate).should == JoinRelation.new(@relation1, @relation2, @predicate)
- end
- end
-end \ No newline at end of file
diff --git a/spec/relations/join_relation_spec.rb b/spec/relations/join_relation_spec.rb
deleted file mode 100644
index ece7e61cc1..0000000000
--- a/spec/relations/join_relation_spec.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe JoinRelation do
- before do
- @relation1 = TableRelation.new(:foo)
- @relation2 = TableRelation.new(:bar)
- @predicate = EqualityPredicate.new(@relation1[:id], @relation2[:id])
- end
-
- describe '==' do
- it 'obtains if the two relations and the predicate are identical' do
- JoinRelation.new(@relation1, @relation2, @predicate).should == JoinRelation.new(@relation1, @relation2, @predicate)
- JoinRelation.new(@relation1, @relation2, @predicate).should_not == JoinRelation.new(@relation1, @relation1, @predicate)
- end
-
- it 'is commutative on the relations' do
- JoinRelation.new(@relation1, @relation2, @predicate).should == JoinRelation.new(@relation2, @relation1, @predicate)
- end
- end
-
- describe '#qualify' do
- it 'distributes over the relations and predicates' do
- InnerJoinRelation.new(@relation1, @relation2, @predicate).qualify. \
- should == InnerJoinRelation.new(@relation1.qualify, @relation2.qualify, @predicate.qualify)
- end
- end
-
- describe '#to_sql' do
- before do
- @relation1 = @relation1.select(@relation1[:id] == @relation2[:foo_id])
- end
-
- it 'manufactures sql joining the two tables on the predicate, merging the selects' do
- InnerJoinRelation.new(@relation1, @relation2, @predicate).to_s.should == SelectBuilder.new do
- select do
- column :foo, :name
- column :foo, :id
- column :bar, :name
- column :bar, :foo_id
- column :bar, :id
- end
- from :foo do
- inner_join :bar do
- equals do
- column :foo, :id
- column :bar, :id
- end
- end
- end
- where do
- equals do
- column :foo, :id
- column :bar, :foo_id
- end
- end
- end.to_s
- end
- end
-end \ No newline at end of file
diff --git a/spec/relations/order_relation_spec.rb b/spec/relations/order_relation_spec.rb
deleted file mode 100644
index a78ac148e2..0000000000
--- a/spec/relations/order_relation_spec.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe OrderRelation do
- before do
- @relation1 = TableRelation.new(:foo)
- @relation2 = TableRelation.new(:bar)
- @attribute1 = @relation1[:id]
- @attribute2 = @relation2[:id]
- end
-
- describe '==' do
- it "obtains if the relation and attributes are identical" do
- OrderRelation.new(@relation1, @attribute1, @attribute2).should == OrderRelation.new(@relation1, @attribute1, @attribute2)
- OrderRelation.new(@relation1, @attribute1).should_not == OrderRelation.new(@relation2, @attribute1)
- OrderRelation.new(@relation1, @attribute1, @attribute2).should_not == OrderRelation.new(@relation1, @attribute2, @attribute1)
- end
- end
-
- describe '#qualify' do
- it "distributes over the relation and attributes" 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_s.should == SelectBuilder.new do
- select do
- column :foo, :name
- column :foo, :id
- end
- from :foo
- order_by do
- column :foo, :id
- end
- end.to_s
- end
- end
-
-end \ No newline at end of file
diff --git a/spec/relations/projection_relation_spec.rb b/spec/relations/projection_relation_spec.rb
deleted file mode 100644
index 5a33b16bd5..0000000000
--- a/spec/relations/projection_relation_spec.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe ProjectionRelation do
- before do
- @relation1 = TableRelation.new(:foo)
- @relation2 = TableRelation.new(:bar)
- @attribute1 = @relation1[:id]
- @attribute2 = @relation2[:id]
- end
-
- describe '==' do
- it "obtains if the relations and attributes are identical" do
- ProjectionRelation.new(@relation1, @attribute1, @attribute2).should == ProjectionRelation.new(@relation1, @attribute1, @attribute2)
- ProjectionRelation.new(@relation1, @attribute1).should_not == ProjectionRelation.new(@relation2, @attribute1)
- ProjectionRelation.new(@relation1, @attribute1).should_not == ProjectionRelation.new(@relation1, @attribute2)
- end
- end
-
- describe '#qualify' do
- it "distributes over teh relation and attributes" 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_s.should == SelectBuilder.new do
- select do
- column :foo, :id
- end
- from :foo
- end.to_s
- end
- end
-end \ No newline at end of file
diff --git a/spec/relations/range_relation_spec.rb b/spec/relations/range_relation_spec.rb
deleted file mode 100644
index 926cc0929f..0000000000
--- a/spec/relations/range_relation_spec.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe RangeRelation do
- before do
- @relation1 = TableRelation.new(:foo)
- @relation2 = TableRelation.new(:bar)
- @range1 = 1..2
- @range2 = 4..9
- end
-
- describe '==' do
- it "obtains if the relation and range are identical" do
- RangeRelation.new(@relation1, @range1).should == RangeRelation.new(@relation1, @range1)
- RangeRelation.new(@relation1, @range1).should_not == RangeRelation.new(@relation2, @range1)
- RangeRelation.new(@relation1, @range1).should_not == RangeRelation.new(@relation1, @range2)
- end
- end
-
- describe '#qualify' do
- it "distributes over the relation and attributes" do
- pending
- end
- end
-
- describe '#to_sql' do
- it "manufactures sql with limit and offset" do
- range_size = @range2.last - @range2.first + 1
- range_start = @range2.first
- RangeRelation.new(@relation1, @range2).to_s.should == SelectBuilder.new do
- select do
- column :foo, :name
- column :foo, :id
- end
- from :foo
- limit range_size
- offset range_start
- end.to_s
- end
- end
-
-end \ No newline at end of file
diff --git a/spec/relations/relation_spec.rb b/spec/relations/relation_spec.rb
deleted file mode 100644
index d029827f21..0000000000
--- a/spec/relations/relation_spec.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe Relation do
- before do
- @relation1 = TableRelation.new(:foo)
- @relation2 = TableRelation.new(:bar)
- @attribute1 = Attribute.new(@relation1, :id)
- @attribute2 = Attribute.new(@relation1, :name)
- end
-
- 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 '<<' do
- it "manufactures a left outer join operation between those two relations" do
- (@relation1 << @relation2).should == LeftOuterJoinOperation.new(@relation1, @relation2)
- end
- end
- end
-
- describe '[]' do
- it "manufactures an attribute when given a symbol" do
- @relation1[:id].should be_eql(Attribute.new(@relation1, :id))
- end
-
- it "manufactures a range relation when given a range" do
- @relation1[1..2].should == RangeRelation.new(@relation1, 1..2)
- end
- end
-
- describe '#include?' do
- it "manufactures an inclusion predicate" do
- @relation1.include?(@attribute1).should == RelationInclusionPredicate.new(@attribute1, @relation1)
- end
- end
-
- describe '#project' do
- it "collapses identical projections" do
- pending
- end
-
- it "manufactures a projection relation" do
- @relation1.project(@attribute1, @attribute2).should == ProjectionRelation.new(@relation1, @attribute1, @attribute2)
- end
- end
-
- describe '#rename' do
- it "manufactures a rename relation" do
- @relation1.rename(@attribute1, :foo).should == RenameRelation.new(@relation1, @attribute1 => :foo)
- end
- end
-
- describe '#select' do
- before do
- @predicate = EqualityPredicate.new(@attribute1, @attribute2)
- end
-
- it "manufactures a selection relation" do
- @relation1.select(@attribute1, @attribute2).should == SelectionRelation.new(@relation1, @attribute1, @attribute2)
- end
- end
-
- describe 'order' do
- it "manufactures an order relation" do
- @relation1.order(@attribute1, @attribute2).should == OrderRelation.new(@relation1, @attribute1, @attribute2)
- end
- end
-end \ No newline at end of file
diff --git a/spec/relations/rename_relation_spec.rb b/spec/relations/rename_relation_spec.rb
deleted file mode 100644
index 301ee6db9e..0000000000
--- a/spec/relations/rename_relation_spec.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-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 "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 "distributes over the relation and renames" 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_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
deleted file mode 100644
index 656a386fd6..0000000000
--- a/spec/relations/selection_relation_spec.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe SelectionRelation do
- before do
- @relation1 = TableRelation.new(:foo)
- @relation2 = TableRelation.new(:bar)
- @predicate1 = EqualityPredicate.new(@relation1[:id], @relation2[:foo_id])
- @predicate2 = LessThanPredicate.new(@relation1[:age], 2)
- end
-
- describe '==' do
- it "obtains if both the predicate and the relation are identical" do
- SelectionRelation.new(@relation1, @predicate1). \
- should == SelectionRelation.new(@relation1, @predicate1)
- SelectionRelation.new(@relation1, @predicate1). \
- should_not == SelectionRelation.new(@relation2, @predicate1)
- SelectionRelation.new(@relation1, @predicate1). \
- should_not == SelectionRelation.new(@relation1, @predicate2)
- end
- end
-
- describe '#initialize' do
- it "manufactures nested selection relations if multiple predicates are provided" do
- SelectionRelation.new(@relation1, @predicate1, @predicate2). \
- should == SelectionRelation.new(SelectionRelation.new(@relation1, @predicate2), @predicate1)
- end
- end
-
- describe '#qualify' do
- it "distributes over the relation and predicates" 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_s.should == SelectBuilder.new do
- select do
- column :foo, :name
- column :foo, :id
- end
- from :foo
- where do
- equals do
- column :foo, :id
- column :bar, :foo_id
- end
- end
- end.to_s
- end
- end
-end \ No newline at end of file
diff --git a/spec/relations/table_relation_spec.rb b/spec/relations/table_relation_spec.rb
deleted file mode 100644
index 0380372344..0000000000
--- a/spec/relations/table_relation_spec.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-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
- @relation.to_sql.should == SelectBuilder.new do |s|
- select do
- column :users, :name
- column :users, :id
- end
- from :users
- end
- end
- end
-
- describe '#attributes' do
- it 'manufactures attributes corresponding to columns in the table' 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