Skip to content

Commit

Permalink
allow arbitrary subs to be added to test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Graham Knop committed Apr 12, 2010
1 parent 22f1a07 commit 0923789
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 1 addition & 3 deletions t/SQL.t
Expand Up @@ -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');
$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');
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 ($sth, $sth2, $rc);
Expand Down Expand Up @@ -298,6 +299,3 @@ cmp_deeply(
'Check table structure',
);

END {
$session->db->dbh->do('DROP TABLE IF EXISTS testTable');
}
7 changes: 5 additions & 2 deletions t/lib/WebGUI/Test.pm
Expand Up @@ -895,6 +895,9 @@ Example call:
my $link = shift;
$link->session->db->write("delete from ldapLink where ldapLinkId=?", [$link->{ldapLinkId}]);
},
'CODE' => sub {
(shift)->();
},
);

sub cleanupGuard {
Expand All @@ -906,9 +909,9 @@ Example call:
my $construct;
if ( ref $class ) {
my $object = $class;
$class = ref $class;
my $cloneSub = $CLASS->_findByIsa($class, \%clone);
$construct = $cloneSub ? sub { $object->$cloneSub } : sub { $object };
$class = ref $class;
}
else {
my $id = shift;
Expand Down Expand Up @@ -958,7 +961,7 @@ sub _findByIsa {
my $toFind = shift;
my $hash = shift;
for my $key ( sort { length $b <=> length $a} keys %$hash ) {
if ($toFind->isa($key)) {
if ($toFind eq $key || $toFind->isa($key)) {
return $hash->{$key};
}
}
Expand Down

0 comments on commit 0923789

Please sign in to comment.