X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fbindtype_columns.t;h=5b83255b64c6ba6bcf556721f7fa953886e61fd9;hb=af8b962fc3f82104ee7067165e3b32a650603220;hp=d88815deb067b1b4b3dd7a34dd8b2bfac4346263;hpb=7af8b477f07d8ae5b759a285ae95d0c0f1697c8a;p=dbsrgits%2FDBIx-Class.git diff --git a/t/bindtype_columns.t b/t/bindtype_columns.t index d88815d..5b83255 100644 --- a/t/bindtype_columns.t +++ b/t/bindtype_columns.t @@ -5,23 +5,56 @@ use Test::More; use lib qw(t/lib); use DBICTest; -my $schema = DBICTest->init_schema(); +my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/}; -plan tests => 2; +plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test' + unless ($dsn && $dbuser); + +plan tests => 3; -#Bindtest -{ - my $new = $schema->resultset("Artist")->new({ - - artistid=>25, - name=>'JohnNapiorkowski', - }); - - $new->update_or_insert; +my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 }); + +my $dbh = $schema->storage->dbh; + +$dbh->do(qq[ + + CREATE TABLE artist + ( + artistid serial NOT NULL PRIMARY KEY, + media bytea NOT NULL, + name varchar NULL + ); +],{ RaiseError => 1, PrintError => 1 }); + + +$schema->class('Artist')->load_components(qw/ + + PK::Auto + Core +/); + +$schema->class('Artist')->add_columns( - my $resultset = $schema->resultset("Artist")->find({artistid=>25}); + "media", { - is($resultset->id, 25, 'Testing New ID'); - is($resultset->name, 'JohnNapiorkowski', 'Testing New Name'); -} + data_type => "bytea", + is_nullable => 0, + }, +); + +# test primary key handling +my $big_long_string = 'abcd' x 250000; + +my $new = $schema->resultset('Artist')->create({ media => $big_long_string }); + +ok($new->artistid, "Created a blob row"); +is($new->media, $big_long_string, "Set the blob correctly."); + +my $rs = $schema->resultset('Artist')->find({artistid=>$new->artistid}); + +is($rs->get_column('media'), $big_long_string, "Created the blob correctly."); + +$dbh->do("DROP TABLE artist"); + +