aboutsummaryrefslogtreecommitdiffstats
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
downloadrails-960bbcb3ce4a82cf4f031d1c6682ce4c1a04474d.tar.gz
rails-960bbcb3ce4a82cf4f031d1c6682ce4c1a04474d.tar.bz2
rails-960bbcb3ce4a82cf4f031d1c6682ce4c1a04474d.zip
initial import
-rw-r--r--README0
-rw-r--r--Rakefile10
-rw-r--r--lib/sql_algebra.rb24
-rw-r--r--lib/sql_algebra/extensions/range.rb0
-rw-r--r--lib/sql_algebra/relations/attribute.rb35
-rw-r--r--lib/sql_algebra/relations/join_operation.rb16
-rw-r--r--lib/sql_algebra/relations/join_relation.rb13
-rw-r--r--lib/sql_algebra/relations/predicates/binary_predicate.rb12
-rw-r--r--lib/sql_algebra/relations/predicates/equality_predicate.rb7
-rw-r--r--lib/sql_algebra/relations/predicates/greater_than_or_equal_to_predicate.rb2
-rw-r--r--lib/sql_algebra/relations/predicates/greater_than_predicate.rb2
-rw-r--r--lib/sql_algebra/relations/predicates/less_than_or_equal_to_predicate.rb2
-rw-r--r--lib/sql_algebra/relations/predicates/less_than_predicate.rb2
-rw-r--r--lib/sql_algebra/relations/predicates/match_predicate.rb7
-rw-r--r--lib/sql_algebra/relations/predicates/predicate.rb5
-rw-r--r--lib/sql_algebra/relations/predicates/range_inclusion_predicate.rb0
-rw-r--r--lib/sql_algebra/relations/predicates/relation_inclusion_predicate.rb11
-rw-r--r--lib/sql_algebra/relations/relation.rb13
-rw-r--r--lib/sql_algebra/relations/table_relation.rb11
-rw-r--r--lib/sql_algebra/sql/select.rb23
-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
31 files changed, 454 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/README
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000000..2557babbc0
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,10 @@
+require 'rubygems'
+require 'spec'
+require 'spec/rake/spectask'
+
+Spec::Rake::SpecTask.new do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+end
+
+desc "Default task is to run specs"
+task :default => :spec \ No newline at end of file
diff --git a/lib/sql_algebra.rb b/lib/sql_algebra.rb
new file mode 100644
index 0000000000..b1816844e4
--- /dev/null
+++ b/lib/sql_algebra.rb
@@ -0,0 +1,24 @@
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+require 'rubygems'
+require 'active_support'
+
+require 'sql_algebra/relations/relation'
+require 'sql_algebra/relations/table_relation'
+require 'sql_algebra/relations/join_operation'
+require 'sql_algebra/relations/join_relation'
+require 'sql_algebra/relations/attribute'
+
+require 'sql_algebra/relations/predicates/predicate'
+require 'sql_algebra/relations/predicates/binary_predicate'
+require 'sql_algebra/relations/predicates/equality_predicate'
+require 'sql_algebra/relations/predicates/less_than_predicate'
+require 'sql_algebra/relations/predicates/less_than_or_equal_to_predicate'
+require 'sql_algebra/relations/predicates/greater_than_predicate'
+require 'sql_algebra/relations/predicates/greater_than_or_equal_to_predicate'
+require 'sql_algebra/relations/predicates/range_inclusion_predicate'
+require 'sql_algebra/relations/predicates/relation_inclusion_predicate'
+require 'sql_algebra/relations/predicates/match_predicate'
+
+require 'sql_algebra/extensions/range'
+
+require 'sql_algebra/sql/select' \ No newline at end of file
diff --git a/lib/sql_algebra/extensions/range.rb b/lib/sql_algebra/extensions/range.rb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/lib/sql_algebra/extensions/range.rb
diff --git a/lib/sql_algebra/relations/attribute.rb b/lib/sql_algebra/relations/attribute.rb
new file mode 100644
index 0000000000..c0b8df3083
--- /dev/null
+++ b/lib/sql_algebra/relations/attribute.rb
@@ -0,0 +1,35 @@
+class Attribute
+ attr_reader :relation, :attribute_name
+
+ def initialize(relation, attribute_name)
+ @relation, @attribute_name = relation, attribute_name
+ end
+
+ def eql?(other)
+ relation == other.relation and attribute_name == other.attribute_name
+ end
+
+ def ==(other)
+ EqualityPredicate.new(self, other)
+ end
+
+ def <(other)
+ LessThanPredicate.new(self, other)
+ end
+
+ def <=(other)
+ LessThanOrEqualToPredicate.new(self, other)
+ end
+
+ def >(other)
+ GreaterThanPredicate.new(self, other)
+ end
+
+ def >=(other)
+ GreaterThanOrEqualToPredicate.new(self, other)
+ end
+
+ def =~(regexp)
+ MatchPredicate.new(self, regexp)
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/join_operation.rb b/lib/sql_algebra/relations/join_operation.rb
new file mode 100644
index 0000000000..dab8e9e6bd
--- /dev/null
+++ b/lib/sql_algebra/relations/join_operation.rb
@@ -0,0 +1,16 @@
+class JoinOperation
+ attr_reader :relation1, :relation2
+
+ def initialize(relation1, relation2)
+ @relation1, @relation2 = relation1, relation2
+ end
+
+ def on(*predicates)
+ JoinRelation.new(relation1, relation2, *predicates)
+ end
+
+ def ==(other)
+ (relation1 == other.relation1 and relation2 == other.relation2) or
+ (relation1 == other.relation2 and relation2 == other.relation1)
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/join_relation.rb b/lib/sql_algebra/relations/join_relation.rb
new file mode 100644
index 0000000000..64db8e0e68
--- /dev/null
+++ b/lib/sql_algebra/relations/join_relation.rb
@@ -0,0 +1,13 @@
+class JoinRelation < Relation
+ attr_reader :relation1, :relation2, :predicates
+
+ def initialize(relation1, relation2, *predicates)
+ @relation1, @relation2, @predicates = relation1, relation2, predicates
+ end
+
+ def ==(other)
+ predicates == other.predicates and
+ ((relation1 == other.relation1 and relation2 == other.relation2) or
+ (relation2 == other.relation1 and relation1 == other.relation2))
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/predicates/binary_predicate.rb b/lib/sql_algebra/relations/predicates/binary_predicate.rb
new file mode 100644
index 0000000000..d7f4cb20e7
--- /dev/null
+++ b/lib/sql_algebra/relations/predicates/binary_predicate.rb
@@ -0,0 +1,12 @@
+class BinaryPredicate < Predicate
+ attr_reader :attribute1, :attribute2
+
+ def initialize(attribute1, attribute2)
+ @attribute1, @attribute2 = attribute1, attribute2
+ end
+
+ def ==(other)
+ super and
+ (attribute1.eql?(other.attribute1) and attribute2.eql?(other.attribute2))
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/predicates/equality_predicate.rb b/lib/sql_algebra/relations/predicates/equality_predicate.rb
new file mode 100644
index 0000000000..2d206e6c12
--- /dev/null
+++ b/lib/sql_algebra/relations/predicates/equality_predicate.rb
@@ -0,0 +1,7 @@
+class EqualityPredicate < BinaryPredicate
+ def ==(other)
+ self.class == other.class and
+ ((attribute1.eql?(other.attribute1) and attribute2.eql?(other.attribute2)) or
+ (attribute1.eql?(other.attribute2) and attribute2.eql?(other.attribute1)))
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/predicates/greater_than_or_equal_to_predicate.rb b/lib/sql_algebra/relations/predicates/greater_than_or_equal_to_predicate.rb
new file mode 100644
index 0000000000..49127c312c
--- /dev/null
+++ b/lib/sql_algebra/relations/predicates/greater_than_or_equal_to_predicate.rb
@@ -0,0 +1,2 @@
+class GreaterThanOrEqualToPredicate < BinaryPredicate
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/predicates/greater_than_predicate.rb b/lib/sql_algebra/relations/predicates/greater_than_predicate.rb
new file mode 100644
index 0000000000..03aecaed62
--- /dev/null
+++ b/lib/sql_algebra/relations/predicates/greater_than_predicate.rb
@@ -0,0 +1,2 @@
+class GreaterThanPredicate < BinaryPredicate
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/predicates/less_than_or_equal_to_predicate.rb b/lib/sql_algebra/relations/predicates/less_than_or_equal_to_predicate.rb
new file mode 100644
index 0000000000..fee6ea7f35
--- /dev/null
+++ b/lib/sql_algebra/relations/predicates/less_than_or_equal_to_predicate.rb
@@ -0,0 +1,2 @@
+class LessThanOrEqualToPredicate < BinaryPredicate
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/predicates/less_than_predicate.rb b/lib/sql_algebra/relations/predicates/less_than_predicate.rb
new file mode 100644
index 0000000000..03cbdcf000
--- /dev/null
+++ b/lib/sql_algebra/relations/predicates/less_than_predicate.rb
@@ -0,0 +1,2 @@
+class LessThanPredicate < BinaryPredicate
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/predicates/match_predicate.rb b/lib/sql_algebra/relations/predicates/match_predicate.rb
new file mode 100644
index 0000000000..90a13090d4
--- /dev/null
+++ b/lib/sql_algebra/relations/predicates/match_predicate.rb
@@ -0,0 +1,7 @@
+class MatchPredicate < Predicate
+ attr_reader :attribute, :regexp
+
+ def initialize(attribute, regexp)
+ @attribute, @regexp = attribute, regexp
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/predicates/predicate.rb b/lib/sql_algebra/relations/predicates/predicate.rb
new file mode 100644
index 0000000000..4c395a3fdc
--- /dev/null
+++ b/lib/sql_algebra/relations/predicates/predicate.rb
@@ -0,0 +1,5 @@
+class Predicate
+ def ==(other)
+ self.class == other.class
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/predicates/range_inclusion_predicate.rb b/lib/sql_algebra/relations/predicates/range_inclusion_predicate.rb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/lib/sql_algebra/relations/predicates/range_inclusion_predicate.rb
diff --git a/lib/sql_algebra/relations/predicates/relation_inclusion_predicate.rb b/lib/sql_algebra/relations/predicates/relation_inclusion_predicate.rb
new file mode 100644
index 0000000000..5881a85d99
--- /dev/null
+++ b/lib/sql_algebra/relations/predicates/relation_inclusion_predicate.rb
@@ -0,0 +1,11 @@
+class RelationInclusionPredicate < Predicate
+ attr_reader :attribute, :relation
+
+ def initialize(attribute, relation)
+ @attribute, @relation = attribute, relation
+ end
+
+ def ==(other)
+ super and attribute == other.attribute and relation == other.relation
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/relation.rb b/lib/sql_algebra/relations/relation.rb
new file mode 100644
index 0000000000..f1f8fc5884
--- /dev/null
+++ b/lib/sql_algebra/relations/relation.rb
@@ -0,0 +1,13 @@
+class Relation
+ def *(other)
+ JoinOperation.new(self, other)
+ end
+
+ def [](attribute_name)
+ Attribute.new(self, attribute_name)
+ end
+
+ def include?(attribute)
+ RelationInclusionPredicate.new(attribute, self)
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/table_relation.rb b/lib/sql_algebra/relations/table_relation.rb
new file mode 100644
index 0000000000..dd4987c3e1
--- /dev/null
+++ b/lib/sql_algebra/relations/table_relation.rb
@@ -0,0 +1,11 @@
+class TableRelation < Relation
+ attr_reader :table
+
+ def initialize(table)
+ @table = table
+ end
+
+ def to_sql
+ Select.new(:*).from(table)
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/sql/select.rb b/lib/sql_algebra/sql/select.rb
new file mode 100644
index 0000000000..da92ad3a52
--- /dev/null
+++ b/lib/sql_algebra/sql/select.rb
@@ -0,0 +1,23 @@
+class Select
+ attr_reader :attributes, :tables, :predicates
+
+ def initialize(*attributes)
+ @attributes = attributes
+ end
+
+ def from(*tables)
+ returning self do |select|
+ @tables = tables
+ end
+ end
+
+ def where(*predicates)
+ returning self do |select|
+ @predicates = predicates
+ end
+ end
+
+ def ==(other)
+ attributes == other.attributes and tables == other.tables and predicates == other.predicates
+ end
+end \ No newline at end of file
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