Exception and class handling for getLastPost in the Thread. Update a test accordingly.

This commit is contained in:
Colin Kuskie 2010-05-20 15:45:28 -07:00
parent 4056d7019e
commit 9e50f5e8c2
2 changed files with 7 additions and 7 deletions

View file

@ -410,12 +410,12 @@ Fetches the last post in this thread, otherwise, returns itself.
sub getLastPost { sub getLastPost {
my $self = shift; my $self = shift;
my $lastPostId = $self->lastPostId; my $lastPostId = $self->lastPostId;
my $lastPost; return $self unless $lastPostId;
if ($lastPostId) { my $lastPost = eval { WebGUI::Asset->newById($self->session, $lastPostId); };
$lastPost = WebGUI::Asset::Post->newById($self->session, $lastPostId); if (Exception::Class->caught()) {
} return $self;
return $lastPost if (defined $lastPost); }
return $self; return $lastPost;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -89,7 +89,7 @@ ok( !$posts->[0]->{'user.isVisitor'}, 'first post made by visitor');
ok( $posts->[0]->{'hideProfileUrl'}, 'hide profile url, and user is visitor'); ok( $posts->[0]->{'hideProfileUrl'}, 'hide profile url, and user is visitor');
ok( !$posts->[0]->{'lastReply.user.isVisitor'}, 'lastReply not made by visitor'); ok( !$posts->[0]->{'lastReply.user.isVisitor'}, 'lastReply not made by visitor');
ok( $posts->[0]->{'lastReply.hideProfileUrl'}, 'lastReply hide profile url, since user is visitor'); ok( $posts->[0]->{'lastReply.hideProfileUrl'}, 'lastReply hide profile url, since user is visitor');
is( $posts->[0]->{'lastReply.url'}, $threads[1]->getUrl.'?pn=1#id'.$threads[1]->getId, 'lastReply url has a query fragment prefixed by "id"'); is( $posts->[0]->{'lastReply.url'}, $threads[1]->getUrl.'#id'.$threads[1]->getId, 'lastReply url has a query fragment prefixed by "id"');
is( $posts->[0]->{'url'}, $threads[1]->getUrl.'#id'.$threads[1]->getId, 'url has a query fragment prefixed by "id"'); is( $posts->[0]->{'url'}, $threads[1]->getUrl.'#id'.$threads[1]->getId, 'url has a query fragment prefixed by "id"');