diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/integration/scratch_spec.rb | 26 | ||||
-rw-r--r-- | spec/relations/join_relation_spec.rb | 11 | ||||
-rw-r--r-- | spec/sql_builder/conditions_spec.rb | 4 | ||||
-rw-r--r-- | spec/sql_builder/select_builder_spec.rb | 30 |
4 files changed, 33 insertions, 38 deletions
diff --git a/spec/integration/scratch_spec.rb b/spec/integration/scratch_spec.rb index 725ac755c0..32ee98d361 100644 --- a/spec/integration/scratch_spec.rb +++ b/spec/integration/scratch_spec.rb @@ -12,30 +12,30 @@ describe 'Relational Algebra' do it 'simulates User.has_many :photos' do @user_photos.project(*@photos.attributes).to_s.should be_like(""" - SELECT photos.id, photos.user_id, photos.camera_id - FROM users - LEFT OUTER JOIN photos - ON users.id = photos.user_id + SELECT `photos`.`id`, `photos`.`user_id`, `photos`.`camera_id` + FROM `users` + LEFT OUTER JOIN `photos` + ON `users`.`id` = `photos`.`user_id` WHERE - users.id = 1 + `users`.`id` = 1 """) end it 'simulates a User.has_many :cameras :through => :photos' do @user_cameras.project(*@cameras.attributes).to_s.should be_like(""" - SELECT cameras.id - FROM users - LEFT OUTER JOIN photos - ON users.id = photos.user_id - LEFT OUTER JOIN cameras - ON photos.camera_id = cameras.id + SELECT `cameras`.`id` + FROM `users` + LEFT OUTER JOIN `photos` + ON `users`.`id` = `photos`.`user_id` + LEFT OUTER JOIN `cameras` + ON `photos`.`camera_id` = `cameras`.`id` WHERE - users.id = 1 + `users`.`id` = 1 """) end it '' do - # @user_cameras.qualify.to_s + # p @user_cameras.qualify.to_s # # @users.rename() end diff --git a/spec/relations/join_relation_spec.rb b/spec/relations/join_relation_spec.rb index b70bf553b1..ece7e61cc1 100644 --- a/spec/relations/join_relation_spec.rb +++ b/spec/relations/join_relation_spec.rb @@ -20,23 +20,18 @@ describe JoinRelation do describe '#qualify' do it 'distributes over the relations and predicates' do - JoinRelation.new(@relation1, @relation2, @predicate).qualify. \ - should == JoinRelation.new(@relation1.qualify, @relation2.qualify, @predicate.qualify) + InnerJoinRelation.new(@relation1, @relation2, @predicate).qualify. \ + should == InnerJoinRelation.new(@relation1.qualify, @relation2.qualify, @predicate.qualify) end end describe '#to_sql' do before do @relation1 = @relation1.select(@relation1[:id] == @relation2[:foo_id]) - class ConcreteJoinRelation < JoinRelation - def join_type - :inner_join - end - end end it 'manufactures sql joining the two tables on the predicate, merging the selects' do - ConcreteJoinRelation.new(@relation1, @relation2, @predicate).to_s.should == SelectBuilder.new do + InnerJoinRelation.new(@relation1, @relation2, @predicate).to_s.should == SelectBuilder.new do select do column :foo, :name column :foo, :id diff --git a/spec/sql_builder/conditions_spec.rb b/spec/sql_builder/conditions_spec.rb index 78590e2631..c1cae902c1 100644 --- a/spec/sql_builder/conditions_spec.rb +++ b/spec/sql_builder/conditions_spec.rb @@ -7,10 +7,10 @@ describe ConditionsBuilder do ConditionsBuilder.new do equals do column(:a, :b) - column(:c, :d, :e) + column(:c, :d, 'e') end end.to_s.should be_like(""" - a.b = e + `a`.`b` = 'e' """) end end diff --git a/spec/sql_builder/select_builder_spec.rb b/spec/sql_builder/select_builder_spec.rb index 7b059bd6bd..060c642c1b 100644 --- a/spec/sql_builder/select_builder_spec.rb +++ b/spec/sql_builder/select_builder_spec.rb @@ -11,7 +11,7 @@ describe SelectBuilder do from :users end.to_s.should be_like(""" SELECT * - FROM users + FROM `users` """) end end @@ -20,13 +20,13 @@ describe SelectBuilder do it 'manufactures correct sql' do SelectBuilder.new do select do - column(:a, :b, :c) - column(:e, :f) + column :a, :b, 'c' + column :e, :f end from :users end.to_s.should be_like(""" - SELECT a.b AS c, e.f - FROM users + SELECT `a`.`b` AS 'c', `e`.`f` + FROM `users` """) end end @@ -40,14 +40,14 @@ describe SelectBuilder do from :users where do equals do - value :a + value 1 column :b, :c end end end.to_s.should be_like(""" SELECT * - FROM users - WHERE a = b.c + FROM `users` + WHERE 1 = `b`.`c` """) end end @@ -61,14 +61,14 @@ describe SelectBuilder do from :users do inner_join(:friendships) do equals do - value :id - value :user_id + column :users, :id + column :friendships, :user_id end end end end.to_s.should be_like(""" SELECT * - FROM users INNER JOIN friendships ON id = user_id + FROM `users` INNER JOIN `friendships` ON `users`.`id` = `friendships`.`user_id` """) end end @@ -82,12 +82,12 @@ describe SelectBuilder do from :users order_by do column :users, :id - column :users, :created_at, :alias + column :users, :created_at, 'alias' end end.to_s.should be_like(""" SELECT * - FROM users - ORDER BY users.id, alias + FROM `users` + ORDER BY `users`.`id`, 'alias' """) end end @@ -103,7 +103,7 @@ describe SelectBuilder do offset 10 end.to_s.should be_like(""" SELECT * - FROM users + FROM `users` LIMIT 10 OFFSET 10 """) |