Commit 030dc146b2827cabe2bd22482ffcf3e116d1caa8
Committed by
Antonio Terceiro
1 parent
3edf1237
Exists in
master
and in
28 other branches
ActionItem1224: not invite when is friend
* Should not create InviteFriend if already is a friend
Showing
2 changed files
with
10 additions
and
3 deletions
Show diff stats
app/controllers/my_profile/friends_controller.rb
@@ -74,10 +74,10 @@ class FriendsController < MyProfileController | @@ -74,10 +74,10 @@ class FriendsController < MyProfileController | ||
74 | end | 74 | end |
75 | 75 | ||
76 | friend = User.find_by_email(friend_email) | 76 | friend = User.find_by_email(friend_email) |
77 | - if !friend.nil? && friend.person.person? | ||
78 | - InviteFriend.create(:person => profile, :friend => friend.person) | ||
79 | - else | 77 | + if friend.nil? |
80 | InviteFriend.create(:person => profile, :friend_name => friend_name, :friend_email => friend_email, :message => params[:message]) | 78 | InviteFriend.create(:person => profile, :friend_name => friend_name, :friend_email => friend_email, :message => params[:message]) |
79 | + elsif !friend.person.is_a_friend?(profile) | ||
80 | + InviteFriend.create(:person => profile, :friend => friend.person) | ||
81 | end | 81 | end |
82 | end | 82 | end |
83 | 83 |
test/functional/friends_controller_test.rb
@@ -157,4 +157,11 @@ class FriendsControllerTest < Test::Unit::TestCase | @@ -157,4 +157,11 @@ class FriendsControllerTest < Test::Unit::TestCase | ||
157 | end | 157 | end |
158 | end | 158 | end |
159 | 159 | ||
160 | + should 'not create InviteFriend if is a friend' do | ||
161 | + friend = create_user('testfriend', :email => 'friend@noosfero.org') | ||
162 | + friend.person.add_friend(profile) | ||
163 | + assert_no_difference InviteFriend, :count do | ||
164 | + post :invite, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :message => "click: <url>", :confirmation => 1, :wizard => true | ||
165 | + end | ||
166 | + end | ||
160 | end | 167 | end |