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