diff --git a/lib/WebGUI/Group.pm b/lib/WebGUI/Group.pm index 6546b5a19..56785f848 100755 --- a/lib/WebGUI/Group.pm +++ b/lib/WebGUI/Group.pm @@ -358,6 +358,20 @@ sub description { } +#------------------------------------------------------------------- + +=head2 DESTROY + +Desconstructor + +=cut + +sub DESTROY { + my $self = shift; + undef $self; +} + + #------------------------------------------------------------------- =head2 expireNotify ( [ value ] ) diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index 74872f865..25259144a 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -276,12 +276,12 @@ sub friends { $self->{_user}{"lastUpdated"} = $self->session->datetime->time(); $self->session->db->write("update users set friendsGroup=?, lastUpdated=? where userId=?", [$myFriends->getId, $self->session->datetime->time(), $self->userId]); - return $myFriends; + $self->{_friendsGroup} = $myFriends; } - elsif (exists $self->{_friendsGroup}) { - return $self->{_friendsGroup}; + elsif (! exists $self->{_friendsGroup}) { + $self->{_friendsGroup} = WebGUI::Group->new($self->session, $self->{_user}{"friendsGroup"}); } - return WebGUI::Group->new($self->session, $self->{_user}{"friendsGroup"}); + return $self->{_friendsGroup}; } #------------------------------------------------------------------- diff --git a/t/User.t b/t/User.t index 1a32edf56..e1f4265a2 100644 --- a/t/User.t +++ b/t/User.t @@ -20,7 +20,7 @@ use WebGUI::Cache; use WebGUI::User; 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; 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', '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 { foreach my $account ($user, $dude, $buster, $buster3, $neighbor, $friend) { (defined $account and ref $account eq 'WebGUI::User') and $account->delete;