aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2007-12-30 11:35:44 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2007-12-30 11:35:44 -0800
commit960bbcb3ce4a82cf4f031d1c6682ce4c1a04474d (patch)
tree24e8e29629450700940d3bdc233265648b5f73f2 /spec
downloadrails-960bbcb3ce4a82cf4f031d1c6682ce4c1a04474d.tar.gz
rails-960bbcb3ce4a82cf4f031d1c6682ce4c1a04474d.tar.bz2
rails-960bbcb3ce4a82cf4f031d1c6682ce4c1a04474d.zip
initial import
Diffstat (limited to 'spec')
-rw-r--r--spec/extensions/range_spec.rb1
-rw-r--r--spec/predicates/binary_predicate_spec.rb27
-rw-r--r--spec/predicates/equality_predicate_spec.rb25
-rw-r--r--spec/predicates/relation_inclusion_predicate_spec.rb16
-rw-r--r--spec/relations/attribute_spec.rb60
-rw-r--r--spec/relations/join_operation_spec.rb29
-rw-r--r--spec/relations/join_relation_spec.rb20
-rw-r--r--spec/relations/relation_spec.rb52
-rw-r--r--spec/relations/table_relation_spec.rb7
-rw-r--r--spec/spec_helper.rb3
-rw-r--r--spec/sql/select_spec.rb19
11 files changed, 259 insertions, 0 deletions
diff --git a/spec/extensions/range_spec.rb b/spec/extensions/range_spec.rb
new file mode 100644
index 0000000000..26ca8978ca
--- /dev/null
+++ b/spec/extensions/range_spec.rb
@@ -0,0 +1 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
diff --git a/spec/predicates/binary_predicate_spec.rb b/spec/predicates/binary_predicate_spec.rb
new file mode 100644
index 0000000000..1be7dd067d
--- /dev/null
+++ b/spec/predicates/binary_predicate_spec.rb
@@ -0,0 +1,27 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe BinaryPredicate do
+ before do
+ @relation1 = TableRelation.new(:foo)
+ @relation2 = TableRelation.new(:bar)
+ @attribute1 = Attribute.new(@relation1, :attribute_name)
+ @attribute2 = Attribute.new(@relation2, :attribute_name)
+ end
+
+ describe BinaryPredicate, '==' do
+ before do
+ class ConcreteBinaryPredicate < BinaryPredicate
+ end
+ end
+
+ it "obtains if attribute1 and attribute2 are identical" do
+ BinaryPredicate.new(@attribute1, @attribute2).should == BinaryPredicate.new(@attribute1, @attribute2)
+ BinaryPredicate.new(@attribute1, @attribute2).should_not == BinaryPredicate.new(@attribute1, @attribute1)
+ end
+
+ it "obtains if the concrete type of the BinaryPredicates are identical" do
+ ConcreteBinaryPredicate.new(@attribute1, @attribute2).should == ConcreteBinaryPredicate.new(@attribute1, @attribute2)
+ BinaryPredicate.new(@attribute1, @attribute2).should_not == ConcreteBinaryPredicate.new(@attribute1, @attribute2)
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/predicates/equality_predicate_spec.rb b/spec/predicates/equality_predicate_spec.rb
new file mode 100644
index 0000000000..18d3399193
--- /dev/null
+++ b/spec/predicates/equality_predicate_spec.rb
@@ -0,0 +1,25 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe EqualityPredicate do
+ before do
+ @relation1 = TableRelation.new(:foo)
+ @relation2 = TableRelation.new(:bar)
+ @attribute1 = Attribute.new(@relation1, :attribute_name)
+ @attribute2 = Attribute.new(@relation2, :attribute_name)
+ end
+
+ describe EqualityPredicate, '==' do
+ it "obtains if attribute1 and attribute2 are identical" do
+ EqualityPredicate.new(@attribute1, @attribute2).should == EqualityPredicate.new(@attribute1, @attribute2)
+ EqualityPredicate.new(@attribute1, @attribute2).should_not == EqualityPredicate.new(@attribute1, @attribute1)
+ end
+
+ it "obtains if the concrete type of the predicates are identical" do
+ EqualityPredicate.new(@attribute1, @attribute2).should_not == BinaryPredicate.new(@attribute1, @attribute2)
+ end
+
+ it "is commutative on the attributes" do
+ EqualityPredicate.new(@attribute1, @attribute2).should == EqualityPredicate.new(@attribute2, @attribute1)
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/predicates/relation_inclusion_predicate_spec.rb b/spec/predicates/relation_inclusion_predicate_spec.rb
new file mode 100644
index 0000000000..6cd37fafa8
--- /dev/null
+++ b/spec/predicates/relation_inclusion_predicate_spec.rb
@@ -0,0 +1,16 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe RelationInclusionPredicate do
+ before do
+ @relation1 = TableRelation.new(:foo)
+ @relation2 = TableRelation.new(:bar)
+ @attribute = @relation1[:baz]
+ end
+
+ describe RelationInclusionPredicate, '==' do
+ it "obtains if attribute1 and attribute2 are identical" do
+ RelationInclusionPredicate.new(@attribute, @relation1).should == RelationInclusionPredicate.new(@attribute, @relation1)
+ RelationInclusionPredicate.new(@attribute, @relation1).should_not == RelationInclusionPredicate.new(@attribute, @relation2)
+ end
+ end
+end \ No newline at end of file
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
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000000..30c1f65f57
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'spec'
+require File.join(File.dirname(__FILE__), '..', 'lib', 'sql_algebra') \ No newline at end of file
diff --git a/spec/sql/select_spec.rb b/spec/sql/select_spec.rb
new file mode 100644
index 0000000000..7d40a20a5b
--- /dev/null
+++ b/spec/sql/select_spec.rb
@@ -0,0 +1,19 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe Select, '==' do
+ it "obtains for queries with identical attributes" do
+ Select.new(:foo).should == Select.new(:foo)
+ Select.new(:bar).should_not == Select.new(:foo)
+ end
+
+ it "obtains for queries with identical tables" do
+ Select.new(:foo).from(:bar).should == Select.new(:foo).from(:bar)
+ Select.new(:foo).from(:bar).should_not == Select.new(:foo).from(:foo)
+ end
+
+ it "obtains for queries with identical predicates" do
+ Select.new(:foo).from(:bar).where(:baz).should == Select.new(:foo).from(:bar).where(:baz)
+ Select.new(:foo).from(:bar).where(:baz).should_not == Select.new(:foo).from(:bar).where(:foo)
+ end
+
+end \ No newline at end of file