2e76bcae515220344c43cbfcd3a1286a3a4001a4
[dbsrgits/DBIx-Class.git] / t / 745db2.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_${_}" } qw/DSN USER PASS/};
9
10 #warn "$dsn $user $pass";
11
12 plan skip_all => 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test'
13   unless ($dsn && $user);
14
15 plan tests => 9;
16
17 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
18
19 my $dbh = $schema->storage->dbh;
20
21 eval { $dbh->do("DROP TABLE artist") };
22
23 $dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10), rank INTEGER DEFAULT 13);");
24
25 # This is in core, just testing that it still loads ok
26 $schema->class('Artist')->load_components('PK::Auto');
27
28 my $ars = $schema->resultset('Artist');
29
30 # test primary key handling
31 my $new = $ars->create({ name => 'foo' });
32 ok($new->artistid, "Auto-PK worked");
33
34 my $init_count = $ars->count;
35 for (1..6) {
36     $ars->create({ name => 'Artist ' . $_ });
37 }
38 is ($ars->count, $init_count + 6, 'Simple count works');
39
40 # test LIMIT support
41 my $it = $ars->search( {},
42   {
43     rows => 3,
44     order_by => 'artistid'
45   }
46 );
47 is( $it->count, 3, "LIMIT count ok" );
48
49 my @all = $it->all;
50 is (@all, 3, 'Number of ->all objects matches count');
51
52 $it->reset
53 is( $it->next->name, "foo", "iterator->next ok" );
54 is( $it->next->name, "Artist 1", "iterator->next ok" );
55 is( $it->next->name, "Artist 2", "iterator->next ok" );
56 is( $it->next, undef, "next past end of resultset ok" );  # this can not succeed if @all > 3
57
58
59 my $test_type_info = {
60     'artistid' => {
61         'data_type' => 'INTEGER',
62         'is_nullable' => 0,
63         'size' => 10
64     },
65     'name' => {
66         'data_type' => 'VARCHAR',
67         'is_nullable' => 1,
68         'size' => 255
69     },
70     'charfield' => {
71         'data_type' => 'CHAR',
72         'is_nullable' => 1,
73         'size' => 10 
74     },
75     'rank' => {
76         'data_type' => 'INTEGER',
77         'is_nullable' => 1,
78         'size' => 10 
79     },
80 };
81
82
83 my $type_info = $schema->storage->columns_info_for('artist');
84 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
85
86 # clean up our mess
87 END {
88     $dbh->do("DROP TABLE artist") if $dbh;
89 }