Only load DBICTest::Schema when needed in tests
[dbsrgits/DBIx-Class.git] / t / 72pg_bytea.t
index 234da7e..186ac89 100644 (file)
@@ -15,7 +15,7 @@ my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/}
 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
   unless ($dsn && $dbuser);
 
-my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
+my $schema = DBICTest->connect_schema($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
 
 if ($schema->storage->_server_info->{normalized_dbms_version} >= 9.0) {
   if (not try { DBD::Pg->VERSION('2.17.2') }) {
@@ -105,7 +105,32 @@ my $new;
   ok($new->bytea eq $big_long_string, 'bytea value made it to db');
 }
 
+# test inserting a row via populate() (bindtype propagation through execute_for_fetch)
+# use a new $dbh to ensure no leakage due to prepare_cached
+{
+  my $cnt = 4;
+
+  $schema->storage->_dbh(undef);
+  my $rs = $schema->resultset('BindType');
+  $rs->delete;
+
+  $rs->populate([
+    [qw/id bytea/],
+    map { [
+      \[ '?', [ {} => $_ ] ],
+      "pop_${_}_" . $big_long_string,
+    ]} (1 .. $cnt)
+  ]);
+
+  is($rs->count, $cnt, 'All rows were correctly inserted');
+  for (1..$cnt) {
+    my $r = $rs->find({ bytea => "pop_${_}_" . $big_long_string });
+    is ($r->id, $_, "Row $_ found after find() on the blob");
+
+  }
+}
+
 done_testing;
 
-eval { $dbh->do("DROP TABLE bindtype_test") };
+eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE bindtype_test") } ) };