Fix for -and conditions when updating or deleting on a ResultSet
[dbsrgits/DBIx-Class.git] / t / run / 12pg.tl
1 sub run_tests {
2 my $schema = shift;
3
4 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
5
6 #warn "$dsn $user $pass";
7
8 plan skip_all, 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
9   . ' (note: creates and drops a table named artist!)' unless ($dsn && $user);
10
11 plan tests => 4;
12
13 DBICTest::Schema->compose_connection('PgTest' => $dsn, $user, $pass);
14
15 my $dbh = PgTest->schema->storage->dbh;
16
17 $dbh->do("CREATE TABLE artist (artistid serial PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));");
18
19 PgTest::Artist->load_components('PK::Auto');
20
21 my $new = PgTest::Artist->create({ name => 'foo' });
22
23 is($new->artistid, 1, "Auto-PK worked");
24
25 $new = PgTest::Artist->create({ name => 'bar' });
26
27 is($new->artistid, 2, "Auto-PK worked");
28
29 my $test_type_info = {
30     'artistid' => {
31         'data_type' => 'integer',
32         'is_nullable' => 0,
33         'size' => 4,
34     },
35     'name' => {
36         'data_type' => 'character varying',
37         'is_nullable' => 1,
38         'size' => 255,
39         'default_value' => undef,
40     },
41     'charfield' => {
42         'data_type' => 'character',
43         'is_nullable' => 1,
44         'size' => 10,
45         'default_value' => undef,
46     },
47 };
48
49
50 my $type_info = PgTest->schema->storage->columns_info_for('artist');
51 my $artistid_defval = delete $type_info->{artistid}->{default_value};
52 like($artistid_defval,
53      qr/^nextval\('public\.artist_artistid_seq'::(?:text|regclass)\)/,
54      'columns_info_for - sequence matches Pg get_autoinc_seq expectations');
55 is_deeply($type_info, $test_type_info,
56           'columns_info_for - column data types');
57
58 $dbh->do("DROP TABLE artist;");
59
60 }
61
62 1;