From b43a12fc92d9fc17e019fd075c305c7bf34870d1 Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Tue, 7 Mar 2017 16:52:31 -0300 Subject: [PATCH] Add spec for `DB.connect` Update to crystal-db ~> 0.4.0 --- shard.yml | 2 +- spec/connection_spec.cr | 11 +++++++++++ spec/spec_helper.cr | 7 +++++++ src/sqlite3/driver.cr | 4 ++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/shard.yml b/shard.yml index 820349c..0f90cf7 100644 --- a/shard.yml +++ b/shard.yml @@ -4,7 +4,7 @@ version: 0.8.1 dependencies: db: github: crystal-lang/crystal-db - version: ~> 0.3.1 + version: ~> 0.4.0 authors: - Ary Borenszweig diff --git a/spec/connection_spec.cr b/spec/connection_spec.cr index 4ff0274..bc28dc8 100644 --- a/spec/connection_spec.cr +++ b/spec/connection_spec.cr @@ -57,4 +57,15 @@ describe Connection do end end end + + it "opens a connection without the pool" do + with_cnn do |cnn| + cnn.should be_a(SQLite3::Connection) + + cnn.exec "create table person (name string, age integer)" + cnn.exec "insert into person values (\"foo\", 10)" + + cnn.scalar("select count(*) from person").should eq(1) + end + end end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 343fd6b..9f55c83 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -12,6 +12,13 @@ ensure File.delete(DB_FILENAME) end +def with_cnn(&block : DB::Connection ->) + File.delete(DB_FILENAME) rescue nil + DB.connect "sqlite3:#{DB_FILENAME}", &block +ensure + File.delete(DB_FILENAME) +end + def with_db(name, &block : DB::Database ->) File.delete(name) rescue nil DB.open "sqlite3:#{name}", &block diff --git a/src/sqlite3/driver.cr b/src/sqlite3/driver.cr index 4f206e6..1ab8430 100644 --- a/src/sqlite3/driver.cr +++ b/src/sqlite3/driver.cr @@ -1,6 +1,6 @@ class SQLite3::Driver < DB::Driver - def build_connection(db) - SQLite3::Connection.new(db) + def build_connection(context : DB::ConnectionContext) + SQLite3::Connection.new(context) end end