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;
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);
}
}

View file

@ -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->()) {