Commit 8502ce1effd6b03a030ac535e13d46960b74ea44
Committed by
Antonio Terceiro
1 parent
6a5b202d
Exists in
staging
and in
42 other branches
ActionItem862: not display add friend button if user already friend
Showing
4 changed files
with
28 additions
and
1 deletions
Show diff stats
app/models/person.rb
app/views/blocks/profile_info_actions/person.rhtml
| 1 | 1 | <ul> |
| 2 | 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 | 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 | 5 | <% end %> |
| 6 | 6 | <% end %> | ... | ... |
test/functional/profile_controller_test.rb
| ... | ... | @@ -223,12 +223,22 @@ class ProfileControllerTest < Test::Unit::TestCase |
| 223 | 223 | end |
| 224 | 224 | |
| 225 | 225 | should 'not display add friend button if user already request friendship' do |
| 226 | + login_as(@profile.identifier) | |
| 226 | 227 | friend = create_user('friendtestuser').person |
| 227 | 228 | AddFriend.create!(:person => @profile, :friend => friend) |
| 228 | 229 | get :index, :profile => friend.identifier |
| 229 | 230 | assert_no_tag :tag => 'a', :content => 'Add friend' |
| 230 | 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 | 242 | should 'show message for disabled enterprise' do |
| 233 | 243 | login_as(@profile.identifier) |
| 234 | 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 < Test::Unit::TestCase |
| 465 | 465 | assert ! person.errors.invalid?(:custom_formation) |
| 466 | 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 | 481 | end | ... | ... |