Commit 8502ce1effd6b03a030ac535e13d46960b74ea44

Authored by Joenio Costa
Committed by Antonio Terceiro
1 parent 6a5b202d

ActionItem862: not display add friend button if user already friend

app/models/person.rb
@@ -215,4 +215,8 @@ class Person < Profile @@ -215,4 +215,8 @@ class Person < Profile
215 organization.tasks.pending.select{|task| self.has_permission?(task.permission, organization)} 215 organization.tasks.pending.select{|task| self.has_permission?(task.permission, organization)}
216 end 216 end
217 217
  218 + def is_a_friend?(person)
  219 + self.friends.include?(person)
  220 + end
  221 +
218 end 222 end
app/views/blocks/profile_info_actions/person.rhtml
1 <ul> 1 <ul>
2 <%if logged_in? && (user != profile) %> 2 <%if logged_in? && (user != profile) %>
3 - <% if !user.already_request_friendship?(profile) %> 3 + <% if !user.already_request_friendship?(profile) and !user.is_a_friend?(profile) %>
4 <li><%= link_to content_tag('span', __('Add friend')), { :profile => user.identifier, :controller => 'friends', :action => 'add', :id => profile.id }, :class => 'button with-text icon-add' %></li> 4 <li><%= link_to content_tag('span', __('Add friend')), { :profile => user.identifier, :controller => 'friends', :action => 'add', :id => profile.id }, :class => 'button with-text icon-add' %></li>
5 <% end %> 5 <% end %>
6 <% end %> 6 <% end %>
test/functional/profile_controller_test.rb
@@ -223,12 +223,22 @@ class ProfileControllerTest &lt; Test::Unit::TestCase @@ -223,12 +223,22 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
223 end 223 end
224 224
225 should 'not display add friend button if user already request friendship' do 225 should 'not display add friend button if user already request friendship' do
  226 + login_as(@profile.identifier)
226 friend = create_user('friendtestuser').person 227 friend = create_user('friendtestuser').person
227 AddFriend.create!(:person => @profile, :friend => friend) 228 AddFriend.create!(:person => @profile, :friend => friend)
228 get :index, :profile => friend.identifier 229 get :index, :profile => friend.identifier
229 assert_no_tag :tag => 'a', :content => 'Add friend' 230 assert_no_tag :tag => 'a', :content => 'Add friend'
230 end 231 end
231 232
  233 + should 'not display add friend button if user already friend' do
  234 + login_as(@profile.identifier)
  235 + friend = create_user('friendtestuser').person
  236 + @profile.add_friend(friend)
  237 + assert @profile.is_a_friend?(friend)
  238 + get :index, :profile => friend.identifier
  239 + assert_no_tag :tag => 'a', :content => 'Add friend'
  240 + end
  241 +
232 should 'show message for disabled enterprise' do 242 should 'show message for disabled enterprise' do
233 login_as(@profile.identifier) 243 login_as(@profile.identifier)
234 ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false) 244 ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false)
test/unit/person_test.rb
@@ -465,4 +465,17 @@ class PersonTest &lt; Test::Unit::TestCase @@ -465,4 +465,17 @@ class PersonTest &lt; Test::Unit::TestCase
465 assert ! person.errors.invalid?(:custom_formation) 465 assert ! person.errors.invalid?(:custom_formation)
466 end 466 end
467 467
  468 + should 'identify when person is a friend' do
  469 + p1 = create_user('testuser1').person
  470 + p2 = create_user('testuser2').person
  471 + p1.add_friend(p2)
  472 + assert p1.is_a_friend?(p2)
  473 + end
  474 +
  475 + should 'identify when person isnt a friend' do
  476 + p1 = create_user('testuser1').person
  477 + p2 = create_user('testuser2').person
  478 + assert !p1.is_a_friend?(p2)
  479 + end
  480 +
468 end 481 end