aboutsummaryrefslogtreecommitdiffstats
path: root/spec
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
parentd43a4e9fc1316fc9eb8ff087c52c7ca7a475c041 (diff)
downloadrails-311f5f8eb588d4cde051762ace87a61425300bec.tar.gz
rails-311f5f8eb588d4cde051762ace87a61425300bec.tar.bz2
rails-311f5f8eb588d4cde051762ace87a61425300bec.zip
minor
Diffstat (limited to 'spec')
-rw-r--r--spec/active_relation/integration/scratch_spec.rb (renamed from spec/integration/scratch_spec.rb)87
-rw-r--r--spec/active_relation/predicates/binary_predicate_spec.rb (renamed from spec/predicates/binary_predicate_spec.rb)2
-rw-r--r--spec/active_relation/predicates/equality_predicate_spec.rb (renamed from spec/predicates/equality_predicate_spec.rb)2
-rw-r--r--spec/active_relation/predicates/relation_inclusion_predicate_spec.rb (renamed from spec/predicates/relation_inclusion_predicate_spec.rb)2
-rw-r--r--spec/active_relation/relations/attribute_spec.rb (renamed from spec/relations/attribute_spec.rb)2
-rw-r--r--spec/active_relation/relations/deletion_relation_spec.rb22
-rw-r--r--spec/active_relation/relations/insertion_relation_spec.rb37
-rw-r--r--spec/active_relation/relations/join_operation_spec.rb (renamed from spec/relations/join_operation_spec.rb)6
-rw-r--r--spec/active_relation/relations/join_relation_spec.rb (renamed from spec/relations/join_relation_spec.rb)2
-rw-r--r--spec/active_relation/relations/order_relation_spec.rb (renamed from spec/relations/order_relation_spec.rb)2
-rw-r--r--spec/active_relation/relations/projection_relation_spec.rb (renamed from spec/relations/projection_relation_spec.rb)2
-rw-r--r--spec/active_relation/relations/range_relation_spec.rb (renamed from spec/relations/range_relation_spec.rb)2
-rw-r--r--spec/active_relation/relations/relation_spec.rb92
-rw-r--r--spec/active_relation/relations/rename_relation_spec.rb (renamed from spec/relations/rename_relation_spec.rb)2
-rw-r--r--spec/active_relation/relations/selection_relation_spec.rb (renamed from spec/relations/selection_relation_spec.rb)2
-rw-r--r--spec/active_relation/relations/table_relation_spec.rb (renamed from spec/relations/table_relation_spec.rb)2
-rw-r--r--spec/active_relation/sql_builder/conditions_spec.rb (renamed from spec/sql_builder/conditions_spec.rb)2
-rw-r--r--spec/active_relation/sql_builder/delete_builder_spec.rb22
-rw-r--r--spec/active_relation/sql_builder/insert_builder_spec.rb24
-rw-r--r--spec/active_relation/sql_builder/select_builder_spec.rb (renamed from spec/sql_builder/select_builder_spec.rb)39
-rw-r--r--spec/debug.log1
-rw-r--r--spec/extensions/range_spec.rb1
-rw-r--r--spec/integration/debug.log0
-rw-r--r--spec/matchers/be_like.rb (renamed from spec/spec_helpers/be_like.rb)0
-rw-r--r--spec/relations/relation_spec.rb72
-rw-r--r--spec/spec_helper.rb7
26 files changed, 321 insertions, 113 deletions
diff --git a/spec/integration/scratch_spec.rb b/spec/active_relation/integration/scratch_spec.rb
index b5d27f1dc2..fba587e4ba 100644
--- a/spec/integration/scratch_spec.rb
+++ b/spec/active_relation/integration/scratch_spec.rb
@@ -1,16 +1,16 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
-describe 'ActiveRelation', 'Proposed refactoring to ActiveRecord, introducing both a SQL
- builder and a Relational Algebra to mediate connections
- between ActiveRecord and the database. The goal of the
- refactoring is to remove code duplication concerning AR
- associations; remove complexity surrounding eager loading;
- comprehensively solve quoting issues; remove the with_scope
- merging logic; minimize the need for with_scope in general;
- simplify the implementation of plugins like HasFinder and
- ActsAsParanoid; introduce an identity map; and allow for
- query optimization. All this while effectively not changing
- the public interface of ActiveRecord.
+describe 'ActiveRelation', 'A proposed refactoring to ActiveRecord, introducing both a SQL
+ Builder and a Relational Algebra to mediate between
+ ActiveRecord and the database. The goal of the refactoring is
+ to remove code duplication concerning AR associations; remove
+ complexity surrounding eager loading; comprehensively solve
+ quoting issues; remove the with_scope merging logic; minimize
+ the need for with_scope in general; simplify the
+ implementation of plugins like HasFinder and ActsAsParanoid;
+ introduce an identity map; and allow for query optimization.
+ All this while remaining backwards-compatible with the
+ existing ActiveRecord interface.
The Relational Algebra makes these ambitious goals
possible. There\'s no need to be scared by the math, it\'s
actually quite simple. Relational Algebras have some nice
@@ -25,7 +25,7 @@ describe 'ActiveRelation', 'Proposed refactoring to ActiveRecord, introducing bo
should all be understood as \'Repositories\': a factory that
given a relation can manufacture objects, and given an object
can manipulate a relation. This may sound trivial, but I
- think it has the potential to make the code much smaller and
+ think it has the potential to make the code smaller and
more consistent.' do
before do
class User < ActiveRecord::Base; has_many :photos end
@@ -40,8 +40,8 @@ describe 'ActiveRelation', 'Proposed refactoring to ActiveRecord, introducing bo
@photos = Photo.relation
@cameras = Camera.relation
# A first taste of a Relational Algebra: User.find(1)
- # == is overridden on attributes to return a predicate, not true or false
@user = @users.select(@users[:id] == 1)
+ # == is overridden on attributes to return a predicate, not true or false
end
# In a Relational Algebra, the various ActiveRecord associations become a simple
@@ -122,13 +122,47 @@ describe 'ActiveRelation', 'Proposed refactoring to ActiveRecord, introducing bo
ON `photos`.`camera_id` = `cameras`.`id`
""")
end
+
+ it 'allows arbitrary sql to be passed through' do
+ (@users << @photos).on("asdf").to_s.should be_like("""
+ SELECT `users`.`name`, `users`.`id`, `photos`.`id`, `photos`.`user_id`, `photos`.`camera_id`
+ FROM `users`
+ LEFT OUTER JOIN `photos`
+ ON asdf
+ """)
+ @users.select("asdf").to_s.should be_like("""
+ SELECT `users`.`name`, `users`.`id`
+ FROM `users`
+ WHERE asdf
+ """)
+ end
+
+ describe 'write operations' do
+ it 'generates the query for user.destroy' do
+ @user.delete.to_s.should be_like("""
+ DELETE
+ FROM `users`
+ WHERE `users`.`id` = 1
+ """)
+ end
- it 'obviates the need for with_scope merging logic since, e.g.,
- `with_scope :conditions => ...` is just a #select operation on the relation' do
+ it 'generates an efficient query for two User.creates -- UnitOfWork is within reach!' do
+ @users.insert(@users[:name] => "humpty").insert(@users[:name] => "dumpty").to_s.should be_like("""
+ INSERT
+ INTO `users`
+ (`users`.`name`) VALUES ('humpty'), ('dumpty')
+ """)
+ end
end
+
+ describe 'with_scope' do
+ it 'obviates the need for with_scope merging logic since, e.g.,
+ `with_scope :conditions => ...` is just a #select operation on the relation' do
+ end
- it 'may eliminate the need for with_scope altogether since the associations no longer
- need it: the relation underlying the association fully encapsulates the scope' do
+ it 'may eliminate the need for with_scope altogether since the associations no longer
+ need it: the relation underlying the association fully encapsulates the scope' do
+ end
end
end
@@ -159,10 +193,11 @@ describe 'ActiveRelation', 'Proposed refactoring to ActiveRecord, introducing bo
describe 'the n+1 problem' do
describe 'the eager join algorithm is vastly simpler' do
- it 'three active records are loaded with only one query' do
+ it 'loads three active records with only one query' do
# using 'rr' mocking framework: the real #select_all is called, but we assert
# that it only happens once:
mock.proxy(ActiveRecord::Base.connection).select_all.with_any_args.once
+
users_cameras = photo_belongs_to_camera(user_has_many_photos(@users)).qualify
user = User.instantiate(users_cameras.first, [:photos => [:camera]])
user.photos.first.camera.attributes.should == {"id" => 1}
@@ -216,11 +251,21 @@ describe 'ActiveRelation', 'Proposed refactoring to ActiveRecord, introducing bo
photos for all subsequent users. This is substantially easier with the
Algebra since we can do @user.join(@photos).on(...) and transform that to
@users.join(@photos).on(...), relying on the IdentityMap to eliminate
- the n+1 problem. This is somewhat similar to ActiveRecordContext but it
- works with every association type, not just belongs_to." do
+ the n+1 problem." do
pending
end
end
end
end
+
+ describe 'The Architecture', 'I propose to produce a new gem, ActiveRelation, which encaplulates
+ the existing ActiveRecord Connection Adapter, the new SQL Builder,
+ and the Relational Algebra. ActiveRecord, then, should no longer
+ interact with the connection object directly.' do
+ end
+
+ describe 'Miscellaneous Ideas' do
+ it 'may be easy to write a SQL parser that can take arbitrary SQL and produce a relation.
+ This has the advantage of permitting e.g., pagination with custom finder_sql'
+ end
end \ No newline at end of file
diff --git a/spec/predicates/binary_predicate_spec.rb b/spec/active_relation/predicates/binary_predicate_spec.rb
index ede44e5175..5de559df41 100644
--- a/spec/predicates/binary_predicate_spec.rb
+++ b/spec/active_relation/predicates/binary_predicate_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe BinaryPredicate do
before do
diff --git a/spec/predicates/equality_predicate_spec.rb b/spec/active_relation/predicates/equality_predicate_spec.rb
index 75b495b6f7..af43b754e0 100644
--- a/spec/predicates/equality_predicate_spec.rb
+++ b/spec/active_relation/predicates/equality_predicate_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe EqualityPredicate do
before do
diff --git a/spec/predicates/relation_inclusion_predicate_spec.rb b/spec/active_relation/predicates/relation_inclusion_predicate_spec.rb
index 6cd37fafa8..f8c911429b 100644
--- a/spec/predicates/relation_inclusion_predicate_spec.rb
+++ b/spec/active_relation/predicates/relation_inclusion_predicate_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe RelationInclusionPredicate do
before do
diff --git a/spec/relations/attribute_spec.rb b/spec/active_relation/relations/attribute_spec.rb
index 4887be38d2..ddfc22fe28 100644
--- a/spec/relations/attribute_spec.rb
+++ b/spec/active_relation/relations/attribute_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe Attribute do
before do
diff --git a/spec/active_relation/relations/deletion_relation_spec.rb b/spec/active_relation/relations/deletion_relation_spec.rb
new file mode 100644
index 0000000000..4f75a261f4
--- /dev/null
+++ b/spec/active_relation/relations/deletion_relation_spec.rb
@@ -0,0 +1,22 @@
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
+
+describe DeletionRelation do
+ before do
+ @relation = TableRelation.new(:users)
+ end
+
+ describe '#to_sql' do
+ it 'manufactures sql deleting the relation' do
+ DeletionRelation.new(@relation.select(@relation[:id] == 1)).to_sql.to_s.should == DeleteBuilder.new do
+ delete
+ from :users
+ where do
+ equals do
+ column :users, :id
+ value 1
+ end
+ end
+ end.to_s
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/active_relation/relations/insertion_relation_spec.rb b/spec/active_relation/relations/insertion_relation_spec.rb
new file mode 100644
index 0000000000..6bafabb473
--- /dev/null
+++ b/spec/active_relation/relations/insertion_relation_spec.rb
@@ -0,0 +1,37 @@
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
+
+describe InsertionRelation do
+ before do
+ @relation = TableRelation.new(:users)
+ end
+
+ describe '#to_sql' do
+ it 'manufactures sql inserting the data for one item' do
+ InsertionRelation.new(@relation, @relation[:name] => "nick").to_sql.should == InsertBuilder.new do
+ insert
+ into :users
+ columns do
+ column :users, :name
+ end
+ values do
+ row "nick"
+ end
+ end
+ end
+
+ it 'manufactures sql inserting the data for multiple items' do
+ nested_insertion = InsertionRelation.new(@relation, @relation[:name] => "cobra")
+ InsertionRelation.new(nested_insertion, nested_insertion[:name] => "commander").to_sql.to_s.should == InsertBuilder.new do
+ insert
+ into :users
+ columns do
+ column :users, :name
+ end
+ values do
+ row "cobra"
+ row "commander"
+ end
+ end.to_s
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/relations/join_operation_spec.rb b/spec/active_relation/relations/join_operation_spec.rb
index db30198f6e..a8ab85123b 100644
--- a/spec/relations/join_operation_spec.rb
+++ b/spec/active_relation/relations/join_operation_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe 'between two relations' do
before do
@@ -31,5 +31,9 @@ describe 'between two relations' do
it "manufactures a join relation of the appropriate type" do
@join_operation.on(@predicate).should == JoinRelation.new(@relation1, @relation2, @predicate)
end
+
+ it "accepts arbitrary strings" do
+ @join_operation.on("arbitrary").should == JoinRelation.new(@relation1, @relation2, "arbitrary")
+ end
end
end \ No newline at end of file
diff --git a/spec/relations/join_relation_spec.rb b/spec/active_relation/relations/join_relation_spec.rb
index ece7e61cc1..d0be270837 100644
--- a/spec/relations/join_relation_spec.rb
+++ b/spec/active_relation/relations/join_relation_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe JoinRelation do
before do
diff --git a/spec/relations/order_relation_spec.rb b/spec/active_relation/relations/order_relation_spec.rb
index a78ac148e2..17f730b564 100644
--- a/spec/relations/order_relation_spec.rb
+++ b/spec/active_relation/relations/order_relation_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe OrderRelation do
before do
diff --git a/spec/relations/projection_relation_spec.rb b/spec/active_relation/relations/projection_relation_spec.rb
index 5a33b16bd5..164c485761 100644
--- a/spec/relations/projection_relation_spec.rb
+++ b/spec/active_relation/relations/projection_relation_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe ProjectionRelation do
before do
diff --git a/spec/relations/range_relation_spec.rb b/spec/active_relation/relations/range_relation_spec.rb
index 926cc0929f..ac9f887d9b 100644
--- a/spec/relations/range_relation_spec.rb
+++ b/spec/active_relation/relations/range_relation_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe RangeRelation do
before do
diff --git a/spec/active_relation/relations/relation_spec.rb b/spec/active_relation/relations/relation_spec.rb
new file mode 100644
index 0000000000..9ed42a98cb
--- /dev/null
+++ b/spec/active_relation/relations/relation_spec.rb
@@ -0,0 +1,92 @@
+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 '[]' 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 'read operations' do
+ 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 '#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(@predicate).should == SelectionRelation.new(@relation1, @predicate)
+ end
+
+ it "accepts arbitrary strings" do
+ @relation1.select("arbitrary").should == SelectionRelation.new(@relation1, "arbitrary")
+ end
+ end
+
+ describe '#order' do
+ it "manufactures an order relation" do
+ @relation1.order(@attribute1, @attribute2).should == OrderRelation.new(@relation1, @attribute1, @attribute2)
+ end
+ end
+ end
+
+ describe 'write operations' do
+ describe '#delete' do
+ it 'manufactures a deletion relation' do
+ @relation1.delete.should == DeletionRelation.new(@relation1)
+ end
+ end
+
+ describe '#insert' do
+ it 'manufactures an insertion relation' do
+ @relation1.insert(tuple = {:id => 1}).should == InsertionRelation.new(@relation1, tuple)
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/relations/rename_relation_spec.rb b/spec/active_relation/relations/rename_relation_spec.rb
index 301ee6db9e..9b1d2d5cc8 100644
--- a/spec/relations/rename_relation_spec.rb
+++ b/spec/active_relation/relations/rename_relation_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe RenameRelation do
before do
diff --git a/spec/relations/selection_relation_spec.rb b/spec/active_relation/relations/selection_relation_spec.rb
index 656a386fd6..c4aadc807b 100644
--- a/spec/relations/selection_relation_spec.rb
+++ b/spec/active_relation/relations/selection_relation_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe SelectionRelation do
before do
diff --git a/spec/relations/table_relation_spec.rb b/spec/active_relation/relations/table_relation_spec.rb
index 0380372344..c943fe6c92 100644
--- a/spec/relations/table_relation_spec.rb
+++ b/spec/active_relation/relations/table_relation_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe TableRelation do
before do
diff --git a/spec/sql_builder/conditions_spec.rb b/spec/active_relation/sql_builder/conditions_spec.rb
index dc44cedc85..dc2d10a2f6 100644
--- a/spec/sql_builder/conditions_spec.rb
+++ b/spec/active_relation/sql_builder/conditions_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe ConditionsBuilder do
describe '#to_s' do
diff --git a/spec/active_relation/sql_builder/delete_builder_spec.rb b/spec/active_relation/sql_builder/delete_builder_spec.rb
new file mode 100644
index 0000000000..fd62fde155
--- /dev/null
+++ b/spec/active_relation/sql_builder/delete_builder_spec.rb
@@ -0,0 +1,22 @@
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
+
+describe DeleteBuilder do
+ describe '#to_s' do
+ it 'manufactures correct sql' do
+ DeleteBuilder.new do
+ delete
+ from :users
+ where do
+ equals do
+ column :users, :id
+ value 1
+ end
+ end
+ end.to_s.should be_like("""
+ DELETE
+ FROM `users`
+ WHERE `users`.`id` = 1
+ """)
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/active_relation/sql_builder/insert_builder_spec.rb b/spec/active_relation/sql_builder/insert_builder_spec.rb
new file mode 100644
index 0000000000..dddc971986
--- /dev/null
+++ b/spec/active_relation/sql_builder/insert_builder_spec.rb
@@ -0,0 +1,24 @@
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
+
+describe InsertBuilder do
+ describe '#to_s' do
+ it 'manufactures correct sql' do
+ InsertBuilder.new do
+ insert
+ into :users
+ columns do
+ column :users, :id
+ column :users, :name
+ end
+ values do
+ row 1, 'bob'
+ row 2, 'moe'
+ end
+ end.to_s.should be_like("""
+ INSERT
+ INTO `users`
+ (`users`.`id`, `users`.`name`) VALUES (1, 'bob'), (2, 'moe')
+ """)
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/sql_builder/select_builder_spec.rb b/spec/active_relation/sql_builder/select_builder_spec.rb
index 122539967e..6539afe0c4 100644
--- a/spec/sql_builder/select_builder_spec.rb
+++ b/spec/active_relation/sql_builder/select_builder_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
describe SelectBuilder do
describe '#to_s' do
@@ -50,6 +50,22 @@ describe SelectBuilder do
WHERE 1 = `b`.`c`
""")
end
+
+ it 'accepts arbitrary strings' do
+ SelectBuilder.new do
+ select do
+ all
+ end
+ from :users
+ where do
+ value "'a' = 'a'"
+ end
+ end.to_s.should be_like("""
+ SELECT *
+ FROM `users`
+ WHERE 'a' = 'a'
+ """)
+ end
end
describe 'with inner join' do
@@ -68,7 +84,26 @@ describe SelectBuilder do
end
end.to_s.should be_like("""
SELECT *
- FROM `users` INNER JOIN `friendships` ON `users`.`id` = `friendships`.`user_id`
+ FROM `users`
+ INNER JOIN `friendships`
+ ON `users`.`id` = `friendships`.`user_id`
+ """)
+ end
+
+ it 'accepts arbitrary on strings' do
+ SelectBuilder.new do
+ select do
+ all
+ end
+ from :users do
+ inner_join :friendships do
+ value "arbitrary"
+ end
+ end
+ end.to_s.should be_like("""
+ SELECT *
+ FROM `users`
+ INNER JOIN `friendships` ON arbitrary
""")
end
end
diff --git a/spec/debug.log b/spec/debug.log
deleted file mode 100644
index d38ed11d82..0000000000
--- a/spec/debug.log
+++ /dev/null
@@ -1 +0,0 @@
-# Logfile created on Tue Jan 01 17:49:28 -0800 2008 by logger.rb/1.5.2.9
diff --git a/spec/extensions/range_spec.rb b/spec/extensions/range_spec.rb
deleted file mode 100644
index 26ca8978ca..0000000000
--- a/spec/extensions/range_spec.rb
+++ /dev/null
@@ -1 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
diff --git a/spec/integration/debug.log b/spec/integration/debug.log
deleted file mode 100644
index e69de29bb2..0000000000
--- a/spec/integration/debug.log
+++ /dev/null
diff --git a/spec/spec_helpers/be_like.rb b/spec/matchers/be_like.rb
index cea3f3027b..cea3f3027b 100644
--- a/spec/spec_helpers/be_like.rb
+++ b/spec/matchers/be_like.rb
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/spec_helper.rb b/spec/spec_helper.rb
index 8d90e0dd51..8f5d76370c 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,8 +1,9 @@
require 'rubygems'
require 'spec'
-require 'rr'
-require File.join(File.dirname(__FILE__), '..', 'lib', 'sql_algebra')
-require File.join(File.dirname(__FILE__), 'spec_helpers', 'be_like')
+dir = File.dirname(__FILE__)
+$LOAD_PATH.unshift "#{dir}/../lib"
+Dir["#{dir}/matchers/*"].each { |m| require "#{dir}/matchers/#{File.basename(m)}" }
+require 'active_relation'
ActiveRecord::Base.configurations = {
'sql_algebra_test' => {