Add exceptions to newPending. Change it to use newById instead of new. Tweak some messages and tests.

This commit is contained in:
Colin Kuskie 2010-01-22 08:40:49 -08:00
parent 90e92184f7
commit 6573884db6
2 changed files with 11 additions and 11 deletions

View file

@ -804,7 +804,7 @@ sub getClassById {
return $className if $className; 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 $class = shift;
my $session = shift; my $session = shift;
my $assetId = shift; my $assetId = shift;
Carp::croak "First parameter to newPending needs to be a WebGUI::Session object" if (!$assetId) {
unless $session && $session->isa('WebGUI::Session'); WebGUI::Error::InvalidParam->throw(error => 'newPending must get an assetId');
Carp::croak "Second parameter to newPending needs to be an assetId" }
unless $assetId; my $revisionDate = $session->db->quickScalar("SELECT revisionDate FROM assetData WHERE assetId = ? ORDER BY revisionDate DESC LIMIT 1", [ $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 ($revisionDate ne "") {
if ($className ne "" || $revisionDate ne "") { return WebGUI::Asset->newById($session, $assetId, $revisionDate);
return WebGUI::Asset->new($session, $assetId, $className, $revisionDate);
} }
else { else {
Carp::croak "Invalid asset id '$assetId' requested!"; WebGUI::Error::InvalidParam->throw(error => "Couldn't lookup revisionDate", param => $assetId);
} }
} }

View file

@ -118,7 +118,7 @@ note "getClassById";
cmp_deeply( cmp_deeply(
$e, $e,
methods( methods(
error => "Couldn't lookup classname", error => "Couldn't lookup className",
param => 'RoysNonExistantAssetId', param => 'RoysNonExistantAssetId',
), ),
'... checking error message', '... checking error message',
@ -519,13 +519,14 @@ isnt( $rootAsset->get('title'), $funkyTitle, 'get returns a safe copy of the Ass
# getIsa # getIsa
# #
################################################################ ################################################################
note "getIsa";
my $node = WebGUI::Asset->getRoot($session); my $node = WebGUI::Asset->getRoot($session);
my $product1 = $node->addChild({ className => 'WebGUI::Asset::Sku::Product'}); my $product1 = $node->addChild({ className => 'WebGUI::Asset::Sku::Product'});
my $product2 = $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 $product3 = $node->addChild({ className => 'WebGUI::Asset::Sku::Product'});
my $getAProduct = WebGUI::Asset::Sku::Product->getIsa($session); 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 $counter = 0;
my $productIds = []; my $productIds = [];
while( my $product = $getAProduct->()) { while( my $product = $getAProduct->()) {