diff options
Diffstat (limited to 'spec/relations')
-rw-r--r-- | spec/relations/attribute_spec.rb | 60 | ||||
-rw-r--r-- | spec/relations/join_operation_spec.rb | 29 | ||||
-rw-r--r-- | spec/relations/join_relation_spec.rb | 20 | ||||
-rw-r--r-- | spec/relations/relation_spec.rb | 52 | ||||
-rw-r--r-- | spec/relations/table_relation_spec.rb | 7 |
5 files changed, 168 insertions, 0 deletions
diff --git a/spec/relations/attribute_spec.rb b/spec/relations/attribute_spec.rb new file mode 100644 index 0000000000..5f2d70ec48 --- /dev/null +++ b/spec/relations/attribute_spec.rb @@ -0,0 +1,60 @@ +require File.join(File.dirname(__FILE__), '..', 'spec_helper') + +describe Attribute do + before do + @relation1 = TableRelation.new(:foo) + @relation2 = TableRelation.new(:bar) + end + + describe Attribute, '#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)) + end + end + + describe Attribute, 'predications' do + before do + @attribute1 = Attribute.new(@relation1, :attribute_name) + @attribute2 = Attribute.new(@relation2, :attribute_name) + end + + describe Attribute, '==' do + it "manufactures an equality predicate" do + (@attribute1 == @attribute2).should == EqualityPredicate.new(@attribute1, @attribute2) + end + end + + describe Attribute, '<' do + it "manufactures a less-than predicate" do + (@attribute1 < @attribute2).should == LessThanPredicate.new(@attribute1, @attribute2) + end + end + + describe Attribute, '<=' do + it "manufactures a less-than or equal-to predicate" do + (@attribute1 <= @attribute2).should == LessThanOrEqualToPredicate.new(@attribute1, @attribute2) + end + end + + describe Attribute, '>' do + it "manufactures a greater-than predicate" do + (@attribute1 > @attribute2).should == GreaterThanPredicate.new(@attribute1, @attribute2) + end + end + + describe Attribute, '>=' do + it "manufactures a greater-than or equal to predicate" do + (@attribute1 >= @attribute2).should == GreaterThanOrEqualToPredicate.new(@attribute1, @attribute2) + end + end + + describe Attribute, '=~' do + it "manufactures a match predicate" do + (@attribute1 =~ /.*/).should == MatchPredicate.new(@attribute1, @attribute2) + end + end + + end +end diff --git a/spec/relations/join_operation_spec.rb b/spec/relations/join_operation_spec.rb new file mode 100644 index 0000000000..13e50e057e --- /dev/null +++ b/spec/relations/join_operation_spec.rb @@ -0,0 +1,29 @@ +require File.join(File.dirname(__FILE__), '..', 'spec_helper') + +describe JoinOperation, 'between two relations' do + before do + @relation1 = TableRelation.new(:foo) + @relation2 = TableRelation.new(:bar) + end + + describe JoinOperation, '==' 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 JoinOperation, 'on' do + before do + @predicate = Predicate.new + end + + it "manufactures a JoinRelation" do + JoinOperation.new(@relation1, @relation2).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 new file mode 100644 index 0000000000..7309563cd5 --- /dev/null +++ b/spec/relations/join_relation_spec.rb @@ -0,0 +1,20 @@ +require File.join(File.dirname(__FILE__), '..', 'spec_helper') + +describe JoinRelation, 'between two relations' do + before do + @relation1 = TableRelation.new(:foo) + @relation2 = TableRelation.new(:bar) + @predicate = Predicate.new + end + + describe JoinRelation, '==' 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 +end
\ No newline at end of file diff --git a/spec/relations/relation_spec.rb b/spec/relations/relation_spec.rb new file mode 100644 index 0000000000..c482eb4a01 --- /dev/null +++ b/spec/relations/relation_spec.rb @@ -0,0 +1,52 @@ +require File.join(File.dirname(__FILE__), '..', 'spec_helper') + +describe Relation do + before do + @relation1 = TableRelation.new(:foo) + @relation2 = TableRelation.new(:bar) + end + + describe Relation, '*' do + it "manufactures a JoinOperation between those two relations" do + (@relation1 * @relation2).should == JoinOperation.new(@relation1, @relation2) + 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 + end + end + + describe Relation, 'include?' do + before do + @attribute = Attribute.new(@relation1, :id) + end + + it "manufactures an inclusion predicate" do + @relation1.include?(@attribute).should == RelationInclusionPredicate.new(@attribute, @relation1) + end + end + + 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 + end + + it "collapses identical projections" do + end + end + + describe Relation, 'select' do + end +end
\ No newline at end of file diff --git a/spec/relations/table_relation_spec.rb b/spec/relations/table_relation_spec.rb new file mode 100644 index 0000000000..dd86f83294 --- /dev/null +++ b/spec/relations/table_relation_spec.rb @@ -0,0 +1,7 @@ +require File.join(File.dirname(__FILE__), '..', 'spec_helper') + +describe TableRelation, '#to_sql' do + it "returns a simple SELECT query" do + TableRelation.new(:users).to_sql.should == Select.new(:*).from(:users) + end +end |