Some testdb changes and alignment, preparing for test refactor branch
[dbsrgits/DBIx-Class.git] / t / bindtype_columns.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, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
9
10 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
11   unless ($dsn && $dbuser);
12   
13 plan tests => 3;
14
15 my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
16
17 my $dbh = $schema->storage->dbh;
18
19 {
20     local $SIG{__WARN__} = sub {};
21     $dbh->do('DROP TABLE IF EXISTS artist');
22     $dbh->do(qq[
23         CREATE TABLE artist
24         (
25             artistid        serial       NOT NULL   PRIMARY KEY,
26             media           bytea        NOT NULL,
27             name            varchar(100) NULL,
28             rank            integer NOT  NULL       DEFAULT '13',
29             charfield       char(10)     NULL
30         );
31     ],{ RaiseError => 1, PrintError => 1 });
32 }
33
34 $schema->class('Artist')->load_components(qw/ 
35
36         PK::Auto 
37         Core 
38 /);
39
40 $schema->class('Artist')->add_columns(
41         
42         "media", { 
43         
44                 data_type => "bytea", 
45                 is_nullable => 0,
46         },
47 );
48
49 # test primary key handling
50 my $big_long_string     = 'abcd' x 250000;
51
52 my $new = $schema->resultset('Artist')->create({ media => $big_long_string });
53
54 ok($new->artistid, "Created a blob row");
55 is($new->media,         $big_long_string, "Set the blob correctly.");
56
57 my $rs = $schema->resultset('Artist')->find({artistid=>$new->artistid});
58
59 is($rs->get_column('media'), $big_long_string, "Created the blob correctly.");
60
61 $dbh->do("DROP TABLE artist");
62
63
64