File: test_database.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 (77 lines) | stat: -rw-r--r-- 2,393 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
68
69
70
71
72
73
74
75
76
77
class TestDatabase < DBDConfig.testbase(:sqlite3)
    def test_database_name
        assert_nothing_raised do
            assert_equal DBDConfig.get_config[dbtype]['dbname'], @dbh.database_name
        end
    end

    def test_disconnect
        assert_nil @dbh.disconnect
        assert_nil @dbh.instance_variable_get("@db")
    end

    def test_columns
        assert_equal [
            {
                :name      => "name",
                :default   => nil,
                :nullable  => true,
                :sql_type  => 100,
                :precision => 255,
                :type_name => "varchar"
            },
            {
                :name      => "age",
                :default   => nil,
                :nullable  => true,
                :sql_type  => 4,
                :type_name => "integer"
            }
        ], @dbh.columns("names")

        assert_equal [
            {
                :name      => "name",
                :default   => nil,
                :nullable  => true,
                :sql_type  => 100,
                :precision => 255,
                :type_name => "varchar"
            },
            {
                :name      => "age",
                :default   => nil,
                :nullable  => true,
                :sql_type  => 4,
                :type_name => "integer"
            }
        ], @dbh.columns("names_defined_with_spaces")
    end
    
    def test_parse_type
      # Some tests to ensure various whitespace and case styles don't confuse parse_type.
      
      match = DBI::DBD::SQLite3.parse_type( 'VARCHAR' )
      assert_equal 'VARCHAR', match[ 1 ]
      
      match = DBI::DBD::SQLite3.parse_type( 'VARCHAR(4096)' )
      assert_equal 'VARCHAR', match[ 1 ]
      assert_equal '4096', match[ 3 ]
      
      match = DBI::DBD::SQLite3.parse_type( 'varchar(4096)' )
      assert_equal 'varchar', match[ 1 ]
      assert_equal '4096', match[ 3 ]
      
      match = DBI::DBD::SQLite3.parse_type( 'VARCHAR( 4096 )' )
      assert_equal 'VARCHAR', match[ 1 ]
      assert_equal '4096', match[ 3 ]
      
      match = DBI::DBD::SQLite3.parse_type( 'VARCHAR ( 4096 )' )
      assert_equal 'VARCHAR', match[ 1 ]
      assert_equal '4096', match[ 3 ]
      
      match = DBI::DBD::SQLite3.parse_type( 'VARCHAR (4096)' )
      assert_equal 'VARCHAR', match[ 1 ]
      assert_equal '4096', match[ 3 ]
    end
end