Fixed broken friends method caching. The cache was never populated, so it
would fail every time. Added a missing DESTROY method to Group.pm. That way it won't puke when trying to call an undefined method when the User object is cleaned up. Added coverage tests for friends method in User.pm
This commit is contained in:
parent
886677c8ce
commit
17441c13c2
3 changed files with 38 additions and 5 deletions
|
|
@ -358,6 +358,20 @@ sub description {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 DESTROY
|
||||||
|
|
||||||
|
Desconstructor
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub DESTROY {
|
||||||
|
my $self = shift;
|
||||||
|
undef $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 expireNotify ( [ value ] )
|
=head2 expireNotify ( [ value ] )
|
||||||
|
|
|
||||||
|
|
@ -276,12 +276,12 @@ sub friends {
|
||||||
$self->{_user}{"lastUpdated"} = $self->session->datetime->time();
|
$self->{_user}{"lastUpdated"} = $self->session->datetime->time();
|
||||||
$self->session->db->write("update users set friendsGroup=?, lastUpdated=? where userId=?",
|
$self->session->db->write("update users set friendsGroup=?, lastUpdated=? where userId=?",
|
||||||
[$myFriends->getId, $self->session->datetime->time(), $self->userId]);
|
[$myFriends->getId, $self->session->datetime->time(), $self->userId]);
|
||||||
return $myFriends;
|
$self->{_friendsGroup} = $myFriends;
|
||||||
}
|
}
|
||||||
elsif (exists $self->{_friendsGroup}) {
|
elsif (! exists $self->{_friendsGroup}) {
|
||||||
return $self->{_friendsGroup};
|
$self->{_friendsGroup} = WebGUI::Group->new($self->session, $self->{_user}{"friendsGroup"});
|
||||||
}
|
}
|
||||||
return WebGUI::Group->new($self->session, $self->{_user}{"friendsGroup"});
|
return $self->{_friendsGroup};
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
21
t/User.t
21
t/User.t
|
|
@ -20,7 +20,7 @@ use WebGUI::Cache;
|
||||||
use WebGUI::User;
|
use WebGUI::User;
|
||||||
use WebGUI::ProfileField;
|
use WebGUI::ProfileField;
|
||||||
|
|
||||||
use Test::More tests => 124; # increment this value for each test you create
|
use Test::More tests => 127; # increment this value for each test you create
|
||||||
use Test::Deep;
|
use Test::Deep;
|
||||||
|
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
@ -533,6 +533,25 @@ is($neighbor->identifier, undef, 'identifier: by default, new users have an unde
|
||||||
is($neighbor->identifier('neighborhood'), 'neighborhood', 'identifier: setting the identifier returns the new identifier');
|
is($neighbor->identifier('neighborhood'), 'neighborhood', 'identifier: setting the identifier returns the new identifier');
|
||||||
is($neighbor->identifier, 'neighborhood', 'identifier: testing fetch of newly set password');
|
is($neighbor->identifier, 'neighborhood', 'identifier: testing fetch of newly set password');
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
#
|
||||||
|
# friends
|
||||||
|
#
|
||||||
|
################################################################
|
||||||
|
|
||||||
|
my $friendsGroup = $neighbor->friends();
|
||||||
|
isa_ok($friendsGroup, 'WebGUI::Group', 'friends returns a Group object');
|
||||||
|
my $friendsGroup2 = $neighbor->friends();
|
||||||
|
cmp_deeply($friendsGroup, $friendsGroup2, 'second fetch returns the cached group object from the user object');
|
||||||
|
|
||||||
|
my $neighborClone = WebGUI::User->new($session, $neighbor->userId);
|
||||||
|
my $friendsGroup3 = $neighborClone->friends();
|
||||||
|
is ($friendsGroup->getId, $friendsGroup3->getId, 'friends: fetching group object when group exists but is not cached');
|
||||||
|
|
||||||
|
undef $friendsGroup2;
|
||||||
|
undef $friendsGroup3;
|
||||||
|
undef $neighborClone;
|
||||||
|
|
||||||
END {
|
END {
|
||||||
foreach my $account ($user, $dude, $buster, $buster3, $neighbor, $friend) {
|
foreach my $account ($user, $dude, $buster, $buster3, $neighbor, $friend) {
|
||||||
(defined $account and ref $account eq 'WebGUI::User') and $account->delete;
|
(defined $account and ref $account eq 'WebGUI::User') and $account->delete;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue