diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index dcfc67e32..332e04555 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1740,8 +1740,10 @@ sub newById { =head2 newByPropertyHashRef ( session, properties ) -Constructor. This creates a standalone asset with no parent. It does not persist that object -to the database. +Constructor. This is a class method. It creates a standalone asset with no parent, with a +varying class, determined by the className entry in the properties hash ref. + +The object created is not persisted to the database. =head3 session @@ -1751,10 +1753,6 @@ A reference to the current session. A hash reference of Asset properties. -=head4 className - -If className is not passed, the class used to call this method will be used in its place. - =cut sub newByPropertyHashRef { @@ -1762,9 +1760,10 @@ sub newByPropertyHashRef { my $session = shift; my $properties = shift || {}; $properties->{className} //= $class; + $properties->{session} = $session; my $className = $class->loadModule($session, $properties->{className}); return undef unless (defined $className); - my $object = $className->new($session, $properties); + my $object = $className->new($properties); return $object; } diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index 3ee544ac3..59795fc4f 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -85,7 +85,7 @@ sub addChild { $session->db->commit; $properties->{assetId} = $id; $properties->{parentId} = $self->getId; - my $temp = WebGUI::Asset->new($session,$properties) || croak "Couldn't create a new $properties->{className} asset!"; + my $temp = WebGUI::Asset->newByPropertyHashRef($session, $properties) || croak "Couldn't create a new $properties->{className} asset!"; my $newAsset = $temp->addRevision($properties, $now, $options); $self->updateHistory("added child ".$id); $session->http->setStatus(201,"Asset Creation Successful"); diff --git a/t/Asset.t b/t/Asset.t index a9a63e66a..32360f4a3 100644 --- a/t/Asset.t +++ b/t/Asset.t @@ -20,7 +20,7 @@ use Test::More; use Test::Deep; use Test::Exception; -plan tests => 46; +plan tests => 49; my $session = WebGUI::Test->session; @@ -141,6 +141,17 @@ my $session = WebGUI::Test->session; is $class, undef, '... returns undef if the class cannot be found'; } +{ + note "newByPropertyHashRef"; + my $asset; + $asset = WebGUI::Asset->newByPropertyHashRef($session, {className => 'WebGUI::Asset::Snippet', title => 'The Shawshank Snippet'}); + isa_ok $asset, 'WebGUI::Asset::Snippet'; + is $asset->title, 'The Shawshank Snippet', 'title is assigned from the property hash'; + + my $a2 = WebGUI::Asset::Snippet->newByPropertyHashRef($session, {}); + isa_ok $asset, 'WebGUI::Asset::Snippet'; +} + { note "new, fetching from db"; my $asset;