From 3fe8f9a080df3c50a2aa3f89e30b2617aaba252b Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Tue, 19 Jun 2012 18:04:12 -0400 Subject: [PATCH] fix nasty data sync bug in WebGUI::User::friends that was causing the friendsGroup assigned to a user t o immediately be lost and replaced a different one in a call to WebGUI::Friends->add, which creates sep erate instances of users --- docs/changelog/7.x.x.txt | 2 ++ lib/WebGUI/User.pm | 11 +++++++++-- t/User.t | 20 +++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 54d45cebd..2515c72ca 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,6 @@ 7.10.25 + - fixed: if user1 adds user2 as a friend, user2 doesn't see user1 as a friend + - fixed: data sync bug in WebGUI::User::friends - added: group() function for Survey::ExpressionEngine to test group membership - added: give WebGUI::PseudoRequest a hostname method - fixed: don't clobber the request handler if WebGUI::Test was loaded inside of mod_perl diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index 824f53850..bda18265b 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -527,11 +527,18 @@ sub friends { my $self = shift; my $myFriends; + # did another copy of this object just get a friends group? + $self->{_user}{friendsGroup} ||= $self->session->db->quickScalar(qq{ + select friendsGroup from users where userId = ? + }, [ + $self->getId, + ]); + # If the user already has a friend group fetch it. - if ( $self->{_user}{"friendsGroup"} ne "" ) { + if ( $self->{_user}{friendsGroup} ) { if ( ! exists $self->{_friendsGroup} ) { # Friends group is not in cache, so instantiate and cache it. - $myFriends = WebGUI::Group->new($self->session, $self->{_user}{"friendsGroup"}); + $myFriends = WebGUI::Group->new($self->session, $self->{_user}{friendsGroup}); $self->{_friendsGroup} = $myFriends; } else { diff --git a/t/User.t b/t/User.t index b1d93359b..0dd00a830 100644 --- a/t/User.t +++ b/t/User.t @@ -22,7 +22,7 @@ use WebGUI::User; use WebGUI::ProfileField; use WebGUI::Shop::AddressBook; -use Test::More tests => 235; # increment this value for each test you create +use Test::More tests => 237; # increment this value for each test you create use Test::Deep; use Data::Dumper; @@ -753,6 +753,24 @@ undef $friendsGroup2; undef $friendsGroup3; undef $neighborClone; +################################################################ +# +# friend reciprication +# +################################################################ +# + +my $buddy1 = WebGUI::User->new($session, 'new'); +WebGUI::Test->addToCleanup($buddy1); + +my $buddy2 = WebGUI::User->new($session, 'new'); +WebGUI::Test->addToCleanup($buddy2); + +WebGUI::Friends->new( $session, $buddy1 )->add( [ $buddy2->userId ] ); + +ok( exists $buddy1->friends->getUserList->{ $buddy2->userId }, 'buddy1 has buddy2 in his friends list' ); +ok( exists $buddy2->friends->getUserList->{ $buddy1->userId }, 'buddy2 has buddy1 in his friends list' ); + ################################################################ # # acceptsPrivateMessages