Add spec for DB.connect

Update to crystal-db ~> 0.4.0
This commit is contained in:
Brian J. Cardiff 2017-03-07 16:52:31 -03:00
parent bbed6256a6
commit b43a12fc92
4 changed files with 21 additions and 3 deletions

View file

@ -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 <aborenszweig@manas.com.ar>

View file

@ -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

View file

@ -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

View file

@ -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