File: test_patches.rb

package info (click to toggle)
ruby-dbd-mysql 0.4.4%2Bgem2deb-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 292 kB
  • ctags: 159
  • sloc: ruby: 1,403; sql: 47; makefile: 2
file content (111 lines) | stat: -rw-r--r-- 3,504 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
class TestMysqlPatches < DBDConfig.testbase(:mysql)
    def test_exception_on_aggregate
        assert_nothing_raised do
            sth = @dbh.prepare("select sum(age) from names")
            sth.execute
            row = sth.fetch 
            assert_equal(70.0, row[0])
            sth.finish

            sth = @dbh.prepare("select count(*) from names")
            sth.execute
            assert_equal([3], sth.fetch)
            sth.finish
        end
    end

    def test_timestamps
        timestamp = "04-06-1978 06:00:00"
        datestamp = "04-06-1978"
        date  = Date.strptime(datestamp, "%m-%d-%Y")
        stamp = DateTime.strptime(timestamp, "%m-%d-%Y %H:%M:%S")
        assert_nothing_raised do
            @sth = @dbh.prepare("insert into db_specific_types_test (ts) values (?)")
            @sth.execute(stamp)
            @sth.finish
        end

        assert_nothing_raised do
            @sth = @dbh.prepare("select ts from db_specific_types_test where ts is not null")
            @sth.execute

            newstamp = @sth.fetch[0]

            assert_equal(newstamp, stamp)
            assert_equal(newstamp.strftime("%m-%d-%Y %H:%M:%S"), timestamp)
            @sth.finish
        end

        assert_nothing_raised do
            @sth = @dbh.prepare("insert into db_specific_types_test (dt) values (?)")
            @sth.execute(date)
            @sth.finish
        end

        assert_nothing_raised do
            @sth = @dbh.prepare("select dt from db_specific_types_test where dt is not null")
            @sth.execute
            
            newdate = @sth.fetch[0]

            assert_equal(newdate, date)
            assert_equal(newdate.strftime("%m-%d-%Y"), datestamp)
            @sth.finish
        end
    end

    # FIXME when the spec is more solid, this should be in the general tests
    def test_columns
        assert_nothing_raised do
            assert_equal [
                {
                    :name =>"foo",
                    :default =>"1",
                    :primary =>true,
                    :scale =>nil,
                    :sql_type =>4,
                    :nullable =>false,
                    :indexed =>true,
                    :precision =>11,
                    :type_name =>"int",
                    :unique =>true
                }
            ], @dbh.columns("field_types_test")
        end

        assert_nothing_raised do
            sth = @dbh.prepare("insert into field_types_test (foo) values (?)")
            sth.execute(2)
            sth.finish
        end

        assert_nothing_raised do
            sth = @dbh.prepare("select * from field_types_test")
            sth.execute
            row = sth.fetch
            columns = sth.column_info
            sth.finish

            assert_equal [2], row
            assert_equal [
                {
                    :dbi_type => DBI::Type::Integer,
                    :name =>"foo",
                    :mysql_type_name =>"INT",
                    :mysql_max_length =>1,
                    :primary =>true,
                    :scale =>0,
                    :mysql_flags =>49155,
                    :sql_type =>4,
                    :nullable =>false,
                    :mysql_type =>3,
                    :indexed =>true,
                    :mysql_length =>11,
                    :precision =>11,
                    :type_name =>"INTEGER",
                    :unique =>true
                }
            ], columns
        end
    end
end