From 12ef6a5ad15078d2f634d3c6cdfc453848f90122 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Tue, 11 Mar 2008 23:22:26 -0700 Subject: refactored session's interaction with engine/connection - follows law of demeter - Table.engine uses AR::Base adapter --- spec/active_relation/unit/relations/deletion_spec.rb | 8 ++++++++ spec/active_relation/unit/relations/insertion_spec.rb | 10 +++++++++- spec/active_relation/unit/relations/relation_spec.rb | 10 +++++++++- spec/active_relation/unit/relations/update_spec.rb | 9 +++++++++ spec/active_relation/unit/session/session_spec.rb | 18 +++++++++--------- spec/spec_helper.rb | 2 +- 6 files changed, 45 insertions(+), 12 deletions(-) (limited to 'spec') diff --git a/spec/active_relation/unit/relations/deletion_spec.rb b/spec/active_relation/unit/relations/deletion_spec.rb index 1f14ae5d34..27d879e96f 100644 --- a/spec/active_relation/unit/relations/deletion_spec.rb +++ b/spec/active_relation/unit/relations/deletion_spec.rb @@ -22,5 +22,13 @@ module ActiveRelation ") end end + + describe '#call' do + it 'executes a delete on the connection' do + deletion = Deletion.new(@relation) + mock(connection = Object.new).delete(deletion.to_sql) + deletion.call(connection) + end + end end end \ No newline at end of file diff --git a/spec/active_relation/unit/relations/insertion_spec.rb b/spec/active_relation/unit/relations/insertion_spec.rb index 91bf7773c1..f081743c50 100644 --- a/spec/active_relation/unit/relations/insertion_spec.rb +++ b/spec/active_relation/unit/relations/insertion_spec.rb @@ -4,16 +4,24 @@ module ActiveRelation describe Insertion do before do @relation = Table.new(:users) + @insertion = Insertion.new(@relation, @relation[:name] => "nick".bind(@relation)) end describe '#to_sql' do it 'manufactures sql inserting the data for one item' do - Insertion.new(@relation, @relation[:name] => "nick".bind(@relation)).to_sql.should be_like(" + @insertion.to_sql.should be_like(" INSERT INTO `users` (`users`.`name`) VALUES ('nick') ") end end + + describe '#call' do + it 'executes an insert on the connection' do + mock(connection = Object.new).insert(@insertion.to_sql) + @insertion.call(connection) + end + end end end \ No newline at end of file diff --git a/spec/active_relation/unit/relations/relation_spec.rb b/spec/active_relation/unit/relations/relation_spec.rb index 8f35760801..2e9f7fd3c8 100644 --- a/spec/active_relation/unit/relations/relation_spec.rb +++ b/spec/active_relation/unit/relations/relation_spec.rb @@ -69,7 +69,7 @@ module ActiveRelation describe '#as' do it "manufactures an alias relation" do - @relation.as(:thucydides).should == Alias.new(@relation, :thucydides) + @relation.as(:paul).should == Alias.new(@relation, :paul) end end @@ -99,6 +99,14 @@ module ActiveRelation end end + describe '#call' do + it 'executes a select_all on the connection' do + mock(connection = Object.new).select_all(@relation.to_sql) + @relation.call(connection) + end + end + + describe '#aggregate' do before do @expression1 = @attribute1.sum diff --git a/spec/active_relation/unit/relations/update_spec.rb b/spec/active_relation/unit/relations/update_spec.rb index cad14fd5ec..848760de83 100644 --- a/spec/active_relation/unit/relations/update_spec.rb +++ b/spec/active_relation/unit/relations/update_spec.rb @@ -22,5 +22,14 @@ module ActiveRelation ") end end + + describe '#call' do + it 'executes an update on the connection' do + update = Update.new(@relation, @relation[:name] => "nick".bind(@relation)) + mock(connection = Object.new).update(update.to_sql) + update.call(connection) + end + end + end end \ No newline at end of file diff --git a/spec/active_relation/unit/session/session_spec.rb b/spec/active_relation/unit/session/session_spec.rb index 89d96ef323..9fba6cc6b2 100644 --- a/spec/active_relation/unit/session/session_spec.rb +++ b/spec/active_relation/unit/session/session_spec.rb @@ -35,39 +35,39 @@ module ActiveRelation @insert = Insertion.new(@relation, @relation[:name] => 'nick'.bind(@relation)) @update = Update.new(@relation, @relation[:name] => 'nick'.bind(@relation)) @delete = Deletion.new(@relation) - @select = @relation + @read = @relation end describe '#create' do it "executes an insertion on the connection" do - mock(@insert.engine).insert(@insert.to_sql) + mock(@insert).call(@insert.engine.connection) @session.create(@insert) end end describe '#read' do it "executes an selection on the connection" do - mock(@select.engine).select_all(@select.to_sql).once - @session.read(@select) + mock(@read).call(@read.engine.connection) + @session.read(@read) end it "is memoized" do - mock(@select.engine).select_all(@select.to_sql).once - @session.read(@select) - @session.read(@select) + mock(@read).call(@read.engine.connection).once + @session.read(@read) + @session.read(@read) end end describe '#update' do it "executes an update on the connection" do - mock(@update.engine).update(@update.to_sql) + mock(@update).call(@update.engine.connection) @session.update(@update) end end describe '#delete' do it "executes a delete on the connection" do - mock(@delete.engine).delete(@delete.to_sql) + mock(@delete).call(@delete.engine.connection) @session.delete(@delete) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6d00064e81..01a703a7d4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -29,6 +29,6 @@ Spec::Runner.configure do |config| config.include(BeLikeMatcher, HashTheSameAsMatcher) config.mock_with :rr config.before do - ActiveRelation::Table.engine = ActiveRecord::Base.connection + ActiveRelation::Table.engine = ActiveRelation::Engine.new(ActiveRecord::Base) end end \ No newline at end of file -- cgit v1.2.3