make statement_specs run over a single connection

This commit is contained in:
Brian J. Cardiff 2016-08-29 16:50:37 -03:00
parent 6e94536a91
commit 6a0a450622
2 changed files with 35 additions and 27 deletions

View file

@ -192,3 +192,11 @@ def with_dummy
yield db yield db
end end
end end
def with_dummy_connection
with_dummy do |db|
db.using_connection do |cnn|
yield cnn.as(DummyDriver::DummyConnection)
end
end
end

View file

@ -2,14 +2,14 @@ require "./spec_helper"
describe DB::Statement do describe DB::Statement do
it "should prepare statements" do it "should prepare statements" do
with_dummy do |db| with_dummy_connection do |cnn|
db.prepare("the query").should be_a(DB::Statement) cnn.prepare("the query").should be_a(DB::Statement)
end end
end end
it "should initialize positional params in query" do it "should initialize positional params in query" do
with_dummy do |db| with_dummy_connection do |cnn|
stmt = db.prepare("the query").as(DummyDriver::DummyStatement) stmt = cnn.prepare("the query").as(DummyDriver::DummyStatement)
stmt.query "a", 1, nil stmt.query "a", 1, nil
stmt.params[0].should eq("a") stmt.params[0].should eq("a")
stmt.params[1].should eq(1) stmt.params[1].should eq(1)
@ -18,8 +18,8 @@ describe DB::Statement do
end end
it "should initialize positional params in query with array" do it "should initialize positional params in query with array" do
with_dummy do |db| with_dummy_connection do |cnn|
stmt = db.prepare("the query").as(DummyDriver::DummyStatement) stmt = cnn.prepare("the query").as(DummyDriver::DummyStatement)
stmt.query ["a", 1, nil] stmt.query ["a", 1, nil]
stmt.params[0].should eq("a") stmt.params[0].should eq("a")
stmt.params[1].should eq(1) stmt.params[1].should eq(1)
@ -28,8 +28,8 @@ describe DB::Statement do
end end
it "should initialize positional params in exec" do it "should initialize positional params in exec" do
with_dummy do |db| with_dummy_connection do |cnn|
stmt = db.prepare("the query").as(DummyDriver::DummyStatement) stmt = cnn.prepare("the query").as(DummyDriver::DummyStatement)
stmt.exec "a", 1, nil stmt.exec "a", 1, nil
stmt.params[0].should eq("a") stmt.params[0].should eq("a")
stmt.params[1].should eq(1) stmt.params[1].should eq(1)
@ -38,8 +38,8 @@ describe DB::Statement do
end end
it "should initialize positional params in exec with array" do it "should initialize positional params in exec with array" do
with_dummy do |db| with_dummy_connection do |cnn|
stmt = db.prepare("the query").as(DummyDriver::DummyStatement) stmt = cnn.prepare("the query").as(DummyDriver::DummyStatement)
stmt.exec ["a", 1, nil] stmt.exec ["a", 1, nil]
stmt.params[0].should eq("a") stmt.params[0].should eq("a")
stmt.params[1].should eq(1) stmt.params[1].should eq(1)
@ -48,8 +48,8 @@ describe DB::Statement do
end end
it "should initialize positional params in scalar" do it "should initialize positional params in scalar" do
with_dummy do |db| with_dummy_connection do |cnn|
stmt = db.prepare("the query").as(DummyDriver::DummyStatement) stmt = cnn.prepare("the query").as(DummyDriver::DummyStatement)
stmt.scalar "a", 1, nil stmt.scalar "a", 1, nil
stmt.params[0].should eq("a") stmt.params[0].should eq("a")
stmt.params[1].should eq(1) stmt.params[1].should eq(1)
@ -58,8 +58,8 @@ describe DB::Statement do
end end
it "query with block should not close statement" do it "query with block should not close statement" do
with_dummy do |db| with_dummy_connection do |cnn|
stmt = db.prepare "3,4 1,2" stmt = cnn.prepare "3,4 1,2"
stmt.query stmt.query
stmt.closed?.should be_false stmt.closed?.should be_false
end end
@ -67,16 +67,16 @@ describe DB::Statement do
it "closing connection should close statement" do it "closing connection should close statement" do
stmt = uninitialized DB::Statement stmt = uninitialized DB::Statement
with_dummy do |db| with_dummy_connection do |cnn|
stmt = db.prepare "3,4 1,2" stmt = cnn.prepare "3,4 1,2"
stmt.query stmt.query
end end
stmt.closed?.should be_true stmt.closed?.should be_true
end end
it "query with block should not close statement" do it "query with block should not close statement" do
with_dummy do |db| with_dummy_connection do |cnn|
stmt = db.prepare "3,4 1,2" stmt = cnn.prepare "3,4 1,2"
stmt.query do |rs| stmt.query do |rs|
end end
stmt.closed?.should be_false stmt.closed?.should be_false
@ -84,8 +84,8 @@ describe DB::Statement do
end end
it "query should not close statement" do it "query should not close statement" do
with_dummy do |db| with_dummy_connection do |cnn|
stmt = db.prepare "3,4 1,2" stmt = cnn.prepare "3,4 1,2"
stmt.query do |rs| stmt.query do |rs|
end end
stmt.closed?.should be_false stmt.closed?.should be_false
@ -93,28 +93,28 @@ describe DB::Statement do
end end
it "scalar should not close statement" do it "scalar should not close statement" do
with_dummy do |db| with_dummy_connection do |cnn|
stmt = db.prepare "3,4 1,2" stmt = cnn.prepare "3,4 1,2"
stmt.scalar stmt.scalar
stmt.closed?.should be_false stmt.closed?.should be_false
end end
end end
it "exec should not close statement" do it "exec should not close statement" do
with_dummy do |db| with_dummy_connection do |cnn|
stmt = db.prepare "3,4 1,2" stmt = cnn.prepare "3,4 1,2"
stmt.exec stmt.exec
stmt.closed?.should be_false stmt.closed?.should be_false
end end
end end
it "connection should cache statements by query" do it "connection should cache statements by query" do
with_dummy do |db| with_dummy_connection do |cnn|
rs = db.query "1, ?", 2 rs = cnn.query "1, ?", 2
stmt = rs.statement stmt = rs.statement
rs.close rs.close
rs = db.query "1, ?", 4 rs = cnn.query "1, ?", 4
rs.statement.should be(stmt) rs.statement.should be(stmt)
end end
end end