File: test_driver.rb

package info (click to toggle)
ruby-dbd-sqlite3 1.2.5%2Bgem2deb-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 268 kB
  • sloc: ruby: 1,179; sql: 33; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 2,196 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class TestDriver < DBDConfig.testbase(:sqlite3)
    def test_require
        require 'dbd/SQLite3'
        assert_kind_of Module, DBI
        assert_kind_of Module, DBI::DBD
        assert_kind_of Module, DBI::DBD::SQLite3
        assert_kind_of Class, DBI::DBD::SQLite3::Driver
        assert_kind_of Class, DBI::DBD::SQLite3::Database
        assert_kind_of Class, DBI::DBD::SQLite3::Statement
    end

    def test_connect
        config = DBDConfig.get_config['sqlite3']

        # this tests DBI more than SQLite, but makes sure our chain works with it.
        dbh = DBI.connect("dbi:SQLite3:" + config['dbname'], nil, nil, {})
        assert dbh
        assert_kind_of DBI::DatabaseHandle, dbh

        # first argument should be a string
        assert_raises(DBI::InterfaceError) do
            DBI::DBD::SQLite3::Driver.new.connect(nil, nil, nil, { })
        end

        # that string should have some frackin' length
        assert_raises(DBI::InterfaceError) do
            DBI::DBD::SQLite3::Driver.new.connect("", nil, nil, { })
        end

        # last argument should be a hash
        assert_raises(DBI::InterfaceError) do
            DBI::DBD::SQLite3::Driver.new.connect(config['dbname'], nil, nil, nil)
        end

        dbh = nil
        driver = nil
        assert_nothing_raised do
            driver = DBI::DBD::SQLite3::Driver.new
            dbh = driver.connect(config['dbname'], nil, nil, { })
        end

        assert_kind_of DBI::DBD::SQLite3::Driver, driver
        assert_kind_of DBI::DBD::SQLite3::Database, dbh

        assert !dbh.instance_variable_get("@autocommit")

        dbh = nil 
        driver = nil
        assert_nothing_raised do
            dbh = DBI::DBD::SQLite3::Driver.new.connect(config['dbname'], nil, nil, { "AutoCommit" => true, "sqlite_full_column_names" => true })
        end
       
        assert dbh
        assert dbh.instance_variable_get("@attr")
        assert_kind_of SQLite3::Database, dbh.instance_variable_get("@db")

        assert File.exists?(config['dbname'])
    end

    def setup
    end

    def teardown
        config = DBDConfig.get_config['sqlite3']
        FileUtils.rm_f(config['dbname'])
    end
end