Check the Asset, not the class, and make sure it is loaded.

This commit is contained in:
Colin Kuskie 2010-03-23 11:54:19 -07:00
parent 4a78377936
commit 22bbf2e23c
3 changed files with 49 additions and 25 deletions

View file

@ -72,6 +72,7 @@ sub addChild {
my $now = shift || $session->datetime->time(); my $now = shift || $session->datetime->time();
my $options = shift; my $options = shift;
# Check for valid parentage using validParent on child's class # Check for valid parentage using validParent on child's class
WebGUI::Asset->loadModule($properties->{className});
if (! $properties->{className}->validParent($session, $self)) { if (! $properties->{className}->validParent($session, $self)) {
return undef; return undef;
} }
@ -997,9 +998,8 @@ sub validParent {
my $session = shift; my $session = shift;
my $asset = shift || $session->asset; my $asset = shift || $session->asset;
my $parent_classes = $class->valid_parent_classes; my $parent_classes = $class->valid_parent_classes;
my $valid_parent = 0;
foreach my $parentClass (@{ $class->valid_parent_classes}) { foreach my $parentClass (@{ $class->valid_parent_classes}) {
return 1 if $class->isa($parentClass); return 1 if $asset->isa($parentClass);
} }
return 0; return 0;
} }

View file

@ -64,31 +64,32 @@ Subclass the method to create a new group for subscribers for the new asset.
=cut =cut
sub duplicate { override duplicate => sub {
my $self = shift; my $self = shift;
my $properties = shift; my $properties = shift;
my $newSelf = $self->next::method( $properties ); my $newSelf = super();
$newSelf->update({ subscriptionGroupId => '' }); $newSelf->update({ subscriptionGroupId => '' });
$newSelf->createSubscriptionGroup; $newSelf->createSubscriptionGroup;
return $newSelf; return $newSelf;
} };
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
=head2 addRevision ( properties [, revisionDate, options ] ) =head2 addRevision ( properties [, revisionDate, options ] )
Override addRevision to set skipNotification to 0 for each new revision. Extend addRevision to set skipNotification to 0 for each new revision.
=cut =cut
sub addRevision { around addRevision => sub {
my $orig = shift;
my $self = shift; my $self = shift;
my $properties = shift; my $properties = shift;
$properties->{ skipNotification } = 0; $properties->{ skipNotification } = 0;
return $self->maybe::next::method( $properties, @_ ); return $self->$orig( $properties, @_ );
} };
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
@ -120,14 +121,14 @@ want to be able to subscribe to children)
=cut =cut
sub commit { override commit => sub {
my ( $self, @args ) = @_; my ( $self, @args ) = @_;
$self->maybe::next::method( @args ); super();
if ( !$self->shouldSkipNotification ) { if ( !$self->shouldSkipNotification ) {
$self->notifySubscribers; $self->notifySubscribers;
} }
return; return;
} };
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
@ -424,16 +425,16 @@ Subclass the method to remove the subscription group.
=cut =cut
sub purge { override purge => sub {
my $self = shift; my $self = shift;
my $options = shift; my $options = shift;
my $group = $self->getSubscriptionGroup(); my $group = $self->getSubscriptionGroup();
$group->delete; $group->delete;
$self->next::method($options); super();
return; return;
} };
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
@ -444,7 +445,7 @@ revision.
=cut =cut
sub setSkipNotification { override setSkipNotification => sub {
my $self = shift; my $self = shift;
my $value = shift; my $value = shift;
$value = defined $value ? $value : 1; $value = defined $value ? $value : 1;
@ -454,7 +455,7 @@ sub setSkipNotification {
} ); } );
return; return;
} };
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
@ -464,10 +465,10 @@ Returns true if the asset should skip notifications.
=cut =cut
sub shouldSkipNotification { override shouldSkipNotification => sub {
my $self = shift; my $self = shift;
return $self->skipNotification ? 1 : 0; return $self->skipNotification ? 1 : 0;
} };
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------

View file

@ -14,13 +14,33 @@ use Test::More;
use Test::Deep; use Test::Deep;
use Test::Exception; use Test::Exception;
use WebGUI::Test; use WebGUI::Test;
use WebGUI::Utility;
sub assetUiLevel { sub assetUiLevel {
return 1; return 1;
} }
sub list_of_tables { sub list_of_tables {
return [qw/assetData/]; return [qw/assetData/];
}
sub getMyParent {
my $test = shift;
my $session = $test->session;
my $parentClasses = $test->class->valid_parent_classes;
my $default = WebGUI::Asset->getDefault($session);
if (WebGUI::Utility::isIn('WebGUI::Asset', @{ $parentClasses}) ) {
return $default;
}
else {
my $class = $parentClasses->[0];
note "Adding a parent of $class";
my $parent = $default->addChild({
className => $class,
}, undef, undef, {skipNotification => 1, skipAutoCommitWorkflows => 1,});
addToCleanup($parent);
return $parent;
}
} }
sub _constructor : Test(4) { sub _constructor : Test(4) {
@ -173,11 +193,14 @@ sub write_update : Test(8) {
sub keywords : Test(3) { sub keywords : Test(3) {
my $test = shift; my $test = shift;
my $session = $test->session; my $session = $test->session;
note "keywords"; note "keywords for ".$test->class;
my $default = WebGUI::Asset->getDefault($session); use Data::Dumper;
my $asset = $default->addChild({ warn Dumper $test->class->valid_parent_classes;
my $parent = $test->getMyParent;
note "got parent and it is a ".ref $parent;
my $asset = $parent->addChild({
className => $test->class, className => $test->class,
}); }, undef, undef, {skipNotification => 1, skipAutoCommitWorkflows => 1,});
addToCleanup($asset); addToCleanup($asset);
can_ok $asset, 'keywords'; can_ok $asset, 'keywords';
$asset->keywords('chess set'); $asset->keywords('chess set');