fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
[dbsrgits/DBIx-Class-Historic.git] / t / 72pg.t
CommitLineData
70350518 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
89add887 8{
9 package DBICTest::Schema::Casecheck;
10
11 use strict;
12 use warnings;
13 use base 'DBIx::Class';
14
15 __PACKAGE__->load_components(qw/PK::Auto Core/);
16 __PACKAGE__->table('casecheck');
17 __PACKAGE__->add_columns(qw/id name NAME uc_name/);
18 __PACKAGE__->set_primary_key('id');
19
20}
21
0567538f 22my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
23
24#warn "$dsn $user $pass";
25
70350518 26plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
ae515736 27 . ' (note: creates and drops tables named artist and casecheck!)' unless ($dsn && $user);
0567538f 28
ae515736 29plan tests => 8;
0567538f 30
89add887 31DBICTest::Schema->load_classes( 'Casecheck' );
70fe6d6e 32DBICTest::Schema->compose_connection('PgTest' => $dsn, $user, $pass);
0567538f 33
a953d8d9 34my $dbh = PgTest->schema->storage->dbh;
4d272ce5 35PgTest->schema->source("Artist")->name("testschema.artist");
36$dbh->do("CREATE SCHEMA testschema;");
ae515736 37$dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));");
38ok ( $dbh->do('CREATE TABLE testschema.casecheck (id serial PRIMARY KEY, "name" VARCHAR(1), "NAME" VARCHAR(2), "UC_NAME" VARCHAR(3));'), 'Creation of casecheck table');
0567538f 39
843f8ecd 40PgTest::Artist->load_components('PK::Auto');
0567538f 41
42my $new = PgTest::Artist->create({ name => 'foo' });
43
b6b65a3e 44is($new->artistid, 1, "Auto-PK worked");
45
46$new = PgTest::Artist->create({ name => 'bar' });
47
48is($new->artistid, 2, "Auto-PK worked");
49
a953d8d9 50my $test_type_info = {
51 'artistid' => {
103e3e03 52 'data_type' => 'integer',
53 'is_nullable' => 0,
fc22fbac 54 'size' => 4,
a953d8d9 55 },
56 'name' => {
103e3e03 57 'data_type' => 'character varying',
58 'is_nullable' => 1,
ae515736 59 'size' => 100,
fc22fbac 60 'default_value' => undef,
103e3e03 61 },
62 'charfield' => {
63 'data_type' => 'character',
a953d8d9 64 'is_nullable' => 1,
fc22fbac 65 'size' => 10,
66 'default_value' => undef,
103e3e03 67 },
a953d8d9 68};
69
fc22fbac 70
4d272ce5 71my $type_info = PgTest->schema->storage->columns_info_for('testschema.artist');
fc22fbac 72my $artistid_defval = delete $type_info->{artistid}->{default_value};
73like($artistid_defval,
4d272ce5 74 qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/,
fc22fbac 75 'columns_info_for - sequence matches Pg get_autoinc_seq expectations');
76is_deeply($type_info, $test_type_info,
77 'columns_info_for - column data types');
a953d8d9 78
ae515736 79my $name_info = PgTest::Casecheck->column_info( 'name' );
80is( $name_info->{size}, 1, "Case sensitive matching info for 'name'" );
81
82my $NAME_info = PgTest::Casecheck->column_info( 'NAME' );
83is( $NAME_info->{size}, 2, "Case sensitive matching info for 'NAME'" );
84
85my $uc_name_info = PgTest::Casecheck->column_info( 'uc_name' );
86is( $uc_name_info->{size}, 3, "Case insensitive matching info for 'uc_name'" );
87
4d272ce5 88$dbh->do("DROP TABLE testschema.artist;");
ae515736 89$dbh->do("DROP TABLE testschema.casecheck;");
4d272ce5 90$dbh->do("DROP SCHEMA testschema;");
0567538f 91