aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/predicates/binary_predicate_spec.rb6
-rw-r--r--spec/relations/order_relation_spec.rb18
-rw-r--r--spec/relations/projection_relation_spec.rb18
-rw-r--r--spec/relations/range_relation_spec.rb18
-rw-r--r--spec/relations/relation_spec.rb23
-rw-r--r--spec/relations/selection_relation_spec.rb28
6 files changed, 105 insertions, 6 deletions
diff --git a/spec/predicates/binary_predicate_spec.rb b/spec/predicates/binary_predicate_spec.rb
index 1be7dd067d..58e395b08d 100644
--- a/spec/predicates/binary_predicate_spec.rb
+++ b/spec/predicates/binary_predicate_spec.rb
@@ -8,6 +8,12 @@ describe BinaryPredicate do
@attribute2 = Attribute.new(@relation2, :attribute_name)
end
+ describe BinaryPredicate, '#initialize' do
+ it "requires that both columns come from the same relation" do
+ pending
+ end
+ end
+
describe BinaryPredicate, '==' do
before do
class ConcreteBinaryPredicate < BinaryPredicate
diff --git a/spec/relations/order_relation_spec.rb b/spec/relations/order_relation_spec.rb
new file mode 100644
index 0000000000..362544d0d1
--- /dev/null
+++ b/spec/relations/order_relation_spec.rb
@@ -0,0 +1,18 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe OrderRelation do
+ before do
+ @relation1 = TableRelation.new(:foo)
+ @relation2 = TableRelation.new(:bar)
+ @attribute1 = @relation1[:foo]
+ @attribute2 = @relation2[:bar]
+ end
+
+ describe OrderRelation, '==' 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
+end \ No newline at end of file
diff --git a/spec/relations/projection_relation_spec.rb b/spec/relations/projection_relation_spec.rb
new file mode 100644
index 0000000000..f802a2e293
--- /dev/null
+++ b/spec/relations/projection_relation_spec.rb
@@ -0,0 +1,18 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe ProjectionRelation do
+ before do
+ @relation1 = TableRelation.new(:foo)
+ @relation2 = TableRelation.new(:bar)
+ @attribute1 = @relation1[:foo]
+ @attribute2 = @relation2[:bar]
+ end
+
+ describe ProjectionRelation, '==' 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
+end \ No newline at end of file
diff --git a/spec/relations/range_relation_spec.rb b/spec/relations/range_relation_spec.rb
new file mode 100644
index 0000000000..2a1cd1d070
--- /dev/null
+++ b/spec/relations/range_relation_spec.rb
@@ -0,0 +1,18 @@
+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 = Time.now..2.days.from_now
+ end
+
+ describe RangeRelation, '==' 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
+end \ No newline at end of file
diff --git a/spec/relations/relation_spec.rb b/spec/relations/relation_spec.rb
index c482eb4a01..7434bd563b 100644
--- a/spec/relations/relation_spec.rb
+++ b/spec/relations/relation_spec.rb
@@ -12,19 +12,17 @@ describe Relation do
end
end
- describe Relation, 'attributes' do
- end
-
describe Relation, '[]' do
it "manufactures a attribute" do
@relation1[:id].should be_eql(Attribute.new(@relation1, :id))
end
it "raises an error if the named attribute is not part of the relation" do
+ pending
end
end
- describe Relation, 'include?' do
+ describe Relation, '#include?' do
before do
@attribute = Attribute.new(@relation1, :id)
end
@@ -34,19 +32,32 @@ describe Relation do
end
end
- describe Relation, 'project' do
+ describe Relation, '#project' do
before do
@attribute1 = Attribute.new(@relation1, :id)
@attribute2 = Attribute.new(@relation1, :name)
end
it "only allows projecting attributes in the relation" do
+ pending
end
it "collapses identical projections" do
+ pending
+ end
+
+ it "manufactures a projected relation" do
+ @relation1.project(@attribute1, @attribute2).should == ProjectedRelation(@relation1, @attribute1, @attribute2)
end
end
- describe Relation, 'select' do
+ describe Relation, '#select' do
+ before do
+ @predicate = EqualityPredicate.new()
+ end
+
+ it "manufactures a selected relation" do
+ @relation1.select(@attribute1, @attribute2).should == SelectedRelation(@relation1, @attribute1, @attribute2)
+ 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
new file mode 100644
index 0000000000..0cfd55449c
--- /dev/null
+++ b/spec/relations/selection_relation_spec.rb
@@ -0,0 +1,28 @@
+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 SelectionRelation, '==' 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 SelectionRelation, '#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
+end \ No newline at end of file