From 6573884db66ceb405e8d1aab286a2810a2594ce3 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 22 Jan 2010 08:40:49 -0800 Subject: [PATCH] Add exceptions to newPending. Change it to use newById instead of new. Tweak some messages and tests. --- lib/WebGUI/Asset.pm | 17 ++++++++--------- t/Asset/Asset.t | 5 +++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index ed9a63b8b..07a5b66f4 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -804,7 +804,7 @@ sub getClassById { return $className if $className; - WebGUI::Error::InvalidParam->throw(error => "Couldn't lookup classname", param => $assetId); + WebGUI::Error::InvalidParam->throw(error => "Couldn't lookup className", param => $assetId); } @@ -1829,16 +1829,15 @@ sub newPending { my $class = shift; my $session = shift; my $assetId = shift; - Carp::croak "First parameter to newPending needs to be a WebGUI::Session object" - unless $session && $session->isa('WebGUI::Session'); - Carp::croak "Second parameter to newPending needs to be an assetId" - unless $assetId; - my ($className, $revisionDate) = $session->db->quickArray("SELECT asset.className, assetData.revisionDate FROM asset INNER JOIN assetData ON asset.assetId = assetData.assetId WHERE asset.assetId = ? ORDER BY assetData.revisionDate DESC LIMIT 1", [ $assetId ]); - if ($className ne "" || $revisionDate ne "") { - return WebGUI::Asset->new($session, $assetId, $className, $revisionDate); + if (!$assetId) { + WebGUI::Error::InvalidParam->throw(error => 'newPending must get an assetId'); + } + my $revisionDate = $session->db->quickScalar("SELECT revisionDate FROM assetData WHERE assetId = ? ORDER BY revisionDate DESC LIMIT 1", [ $assetId ]); + if ($revisionDate ne "") { + return WebGUI::Asset->newById($session, $assetId, $revisionDate); } else { - Carp::croak "Invalid asset id '$assetId' requested!"; + WebGUI::Error::InvalidParam->throw(error => "Couldn't lookup revisionDate", param => $assetId); } } diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index aec9e1648..3abca8d1a 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -118,7 +118,7 @@ note "getClassById"; cmp_deeply( $e, methods( - error => "Couldn't lookup classname", + error => "Couldn't lookup className", param => 'RoysNonExistantAssetId', ), '... checking error message', @@ -519,13 +519,14 @@ isnt( $rootAsset->get('title'), $funkyTitle, 'get returns a safe copy of the Ass # getIsa # ################################################################ +note "getIsa"; my $node = WebGUI::Asset->getRoot($session); my $product1 = $node->addChild({ className => 'WebGUI::Asset::Sku::Product'}); my $product2 = $node->addChild({ className => 'WebGUI::Asset::Sku::Product'}); my $product3 = $node->addChild({ className => 'WebGUI::Asset::Sku::Product'}); my $getAProduct = WebGUI::Asset::Sku::Product->getIsa($session); -isa_ok($getAProduct, 'CODE', 'getIsa returns a sub ref'); +isa_ok($getAProduct, 'CODE'); my $counter = 0; my $productIds = []; while( my $product = $getAProduct->()) {