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

View file

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

View file

@ -14,6 +14,7 @@ use Test::More;
use Test::Deep;
use Test::Exception;
use WebGUI::Test;
use WebGUI::Utility;
sub assetUiLevel {
return 1;
@ -23,6 +24,25 @@ sub list_of_tables {
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) {
my $test = shift;
my $session = $test->session;
@ -173,11 +193,14 @@ sub write_update : Test(8) {
sub keywords : Test(3) {
my $test = shift;
my $session = $test->session;
note "keywords";
my $default = WebGUI::Asset->getDefault($session);
my $asset = $default->addChild({
note "keywords for ".$test->class;
use Data::Dumper;
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,
});
}, undef, undef, {skipNotification => 1, skipAutoCommitWorkflows => 1,});
addToCleanup($asset);
can_ok $asset, 'keywords';
$asset->keywords('chess set');