aboutsummaryrefslogtreecommitdiffstats
path: root/spec/algebra/unit/session
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-03-12 14:46:37 -0800
committerCarl Lerche <carllerche@mac.com>2010-03-12 14:46:37 -0800
commite13420c86afb5c31e90cff800f121bd49255b939 (patch)
tree7089d188061b2a676143add52227e107a5cf9b45 /spec/algebra/unit/session
parent0b8b87fb947a746d4e58d11ea73ef20cfb23f576 (diff)
downloadrails-e13420c86afb5c31e90cff800f121bd49255b939.tar.gz
rails-e13420c86afb5c31e90cff800f121bd49255b939.tar.bz2
rails-e13420c86afb5c31e90cff800f121bd49255b939.zip
We're obviously writing specs for arel. No need for a sub directory.
Diffstat (limited to 'spec/algebra/unit/session')
-rw-r--r--spec/algebra/unit/session/session_spec.rb84
1 files changed, 84 insertions, 0 deletions
diff --git a/spec/algebra/unit/session/session_spec.rb b/spec/algebra/unit/session/session_spec.rb
new file mode 100644
index 0000000000..0553a140ec
--- /dev/null
+++ b/spec/algebra/unit/session/session_spec.rb
@@ -0,0 +1,84 @@
+require 'spec_helper'
+
+module Arel
+ describe Session do
+ before do
+ @relation = Table.new(:users)
+ @session = Session.new
+ end
+
+ describe '::start' do
+ describe '::instance' do
+ it "it is a singleton within the started session" do
+ Session.start do
+ Session.new.should == Session.new
+ end
+ end
+
+ it "is a singleton across nested sessions" do
+ Session.start do
+ outside = Session.new
+ Session.start do
+ Session.new.should == outside
+ end
+ end
+ end
+
+ it "manufactures new sessions outside of the started session" do
+ Session.new.should_not == Session.new
+ end
+ end
+ end
+
+ describe Session::CRUD do
+ before do
+ @insert = Insert.new(@relation, @relation[:name] => 'nick')
+ @update = Update.new(@relation, @relation[:name] => 'nick')
+ @delete = Deletion.new(@relation)
+ @read = @relation
+ end
+
+ describe '#create' do
+ it "executes an insertion on the connection" do
+ @insert.should_receive(:call)
+ @session.create(@insert)
+ end
+ end
+
+ describe '#read' do
+ it "executes an selection on the connection" do
+ @read.should_receive(:call)
+ @session.read(@read)
+ end
+
+ it "is memoized" do
+ @read.should_receive(:call).once
+ @session.read(@read)
+ @session.read(@read)
+ end
+ end
+
+ describe '#update' do
+ it "executes an update on the connection" do
+ @update.should_receive(:call)
+ @session.update(@update)
+ end
+ end
+
+ describe '#delete' do
+ it "executes a delete on the connection" do
+ @delete.should_receive(:call)
+ @session.delete(@delete)
+ end
+ end
+ end
+
+ describe 'Transactions' do
+ describe '#begin' do
+ end
+
+ describe '#end' do
+ end
+ end
+ end
+end