Incorporate changes in -current.
[dbsrgits/DBIx-Class.git] / t / 72pg.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_PG_${_}" } qw/DSN USER PASS/};
9
10 #warn "$dsn $user $pass";
11
12 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
13  . ' (note: creates and drops tables named artist and casecheck!)' unless ($dsn && $user);
14
15 plan tests => 8;
16
17 DBICTest::Schema->compose_connection('PgTest' => $dsn, $user, $pass);
18
19 my $dbh = PgTest->schema->storage->dbh;
20 PgTest->schema->source("Artist")->name("testschema.artist");
21 $dbh->do("CREATE SCHEMA testschema;");
22 $dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));");
23 ok ( $dbh->do('CREATE TABLE testschema.casecheck (id serial PRIMARY KEY, "name" VARCHAR(1), "NAME" VARCHAR(2), "UC_NAME" VARCHAR(3));'), 'Creation of casecheck table');
24
25 PgTest::Artist->load_components('PK::Auto');
26
27 my $new = PgTest::Artist->create({ name => 'foo' });
28
29 is($new->artistid, 1, "Auto-PK worked");
30
31 $new = PgTest::Artist->create({ name => 'bar' });
32
33 is($new->artistid, 2, "Auto-PK worked");
34
35 my $test_type_info = {
36     'artistid' => {
37         'data_type' => 'integer',
38         'is_nullable' => 0,
39         'size' => 4,
40     },
41     'name' => {
42         'data_type' => 'character varying',
43         'is_nullable' => 1,
44         'size' => 100,
45         'default_value' => undef,
46     },
47     'charfield' => {
48         'data_type' => 'character',
49         'is_nullable' => 1,
50         'size' => 10,
51         'default_value' => undef,
52     },
53 };
54
55
56 my $type_info = PgTest->schema->storage->columns_info_for('testschema.artist');
57 my $artistid_defval = delete $type_info->{artistid}->{default_value};
58 like($artistid_defval,
59      qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/,
60      'columns_info_for - sequence matches Pg get_autoinc_seq expectations');
61 is_deeply($type_info, $test_type_info,
62           'columns_info_for - column data types');
63
64 my $name_info = PgTest::Casecheck->column_info( 'name' );
65 is( $name_info->{size}, 1, "Case sensitive matching info for 'name'" );
66
67 my $NAME_info = PgTest::Casecheck->column_info( 'NAME' );
68 is( $NAME_info->{size}, 2, "Case sensitive matching info for 'NAME'" );
69
70 my $uc_name_info = PgTest::Casecheck->column_info( 'uc_name' );
71 is( $uc_name_info->{size}, 3, "Case insensitive matching info for 'uc_name'" );
72
73 $dbh->do("DROP TABLE testschema.artist;");
74 $dbh->do("DROP TABLE testschema.casecheck;");
75 $dbh->do("DROP SCHEMA testschema;");
76