allow arbitrary subs to be added to test cleanup

This commit is contained in:
Graham Knop 2010-04-10 14:08:26 -05:00
parent 15939961bb
commit eb97a8d50e
2 changed files with 6 additions and 5 deletions

View file

@ -174,6 +174,7 @@ SKIP: {
skip("No InnoDB tables in this MySQL. Skipping all transaction related tests.",7) if (lc $mysqlVariables{have_innodb} ne 'yes'); skip("No InnoDB tables in this MySQL. Skipping all transaction related tests.",7) if (lc $mysqlVariables{have_innodb} ne 'yes');
$session->db->dbh->do('DROP TABLE IF EXISTS testTable'); $session->db->dbh->do('DROP TABLE IF EXISTS testTable');
$session->db->dbh->do('CREATE TABLE testTable (myIndex int(8) NOT NULL default 0, message CHAR(64), PRIMARY KEY(myIndex)) TYPE=InnoDB'); $session->db->dbh->do('CREATE TABLE testTable (myIndex int(8) NOT NULL default 0, message CHAR(64), PRIMARY KEY(myIndex)) TYPE=InnoDB');
addToCleanup( sub { $session->db->dbh->do('DROP TABLE testTable') });
my $dbh2 = WebGUI::SQL->connect($session,$session->config->get("dsn"), $session->config->get("dbuser"), $session->config->get("dbpass")); my $dbh2 = WebGUI::SQL->connect($session,$session->config->get("dsn"), $session->config->get("dbuser"), $session->config->get("dbpass"));
my ($sth, $sth2, $rc); my ($sth, $sth2, $rc);
@ -298,6 +299,3 @@ cmp_deeply(
'Check table structure', 'Check table structure',
); );
END {
$session->db->dbh->do('DROP TABLE IF EXISTS testTable');
}

View file

@ -895,6 +895,9 @@ Example call:
my $link = shift; my $link = shift;
$link->session->db->write("delete from ldapLink where ldapLinkId=?", [$link->{ldapLinkId}]); $link->session->db->write("delete from ldapLink where ldapLinkId=?", [$link->{ldapLinkId}]);
}, },
'CODE' => sub {
(shift)->();
},
); );
sub cleanupGuard { sub cleanupGuard {
@ -906,9 +909,9 @@ Example call:
my $construct; my $construct;
if ( ref $class ) { if ( ref $class ) {
my $object = $class; my $object = $class;
$class = ref $class;
my $cloneSub = $CLASS->_findByIsa($class, \%clone); my $cloneSub = $CLASS->_findByIsa($class, \%clone);
$construct = $cloneSub ? sub { $object->$cloneSub } : sub { $object }; $construct = $cloneSub ? sub { $object->$cloneSub } : sub { $object };
$class = ref $class;
} }
else { else {
my $id = shift; my $id = shift;
@ -958,7 +961,7 @@ sub _findByIsa {
my $toFind = shift; my $toFind = shift;
my $hash = shift; my $hash = shift;
for my $key ( sort { length $b <=> length $a} keys %$hash ) { for my $key ( sort { length $b <=> length $a} keys %$hash ) {
if ($toFind->isa($key)) { if ($toFind eq $key || $toFind->isa($key)) {
return $hash->{$key}; return $hash->{$key};
} }
} }