diff --git a/app/models/person.rb b/app/models/person.rb
index 7e8c8c3..e52bc76 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -215,4 +215,8 @@ class Person < Profile
organization.tasks.pending.select{|task| self.has_permission?(task.permission, organization)}
end
+ def is_a_friend?(person)
+ self.friends.include?(person)
+ end
+
end
diff --git a/app/views/blocks/profile_info_actions/person.rhtml b/app/views/blocks/profile_info_actions/person.rhtml
index d43cc65..cf7854a 100644
--- a/app/views/blocks/profile_info_actions/person.rhtml
+++ b/app/views/blocks/profile_info_actions/person.rhtml
@@ -1,6 +1,6 @@
<%if logged_in? && (user != profile) %>
- <% if !user.already_request_friendship?(profile) %>
+ <% if !user.already_request_friendship?(profile) and !user.is_a_friend?(profile) %>
- <%= link_to content_tag('span', __('Add friend')), { :profile => user.identifier, :controller => 'friends', :action => 'add', :id => profile.id }, :class => 'button with-text icon-add' %>
<% end %>
<% end %>
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index d54b86b..ef7a99e 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -223,12 +223,22 @@ class ProfileControllerTest < Test::Unit::TestCase
end
should 'not display add friend button if user already request friendship' do
+ login_as(@profile.identifier)
friend = create_user('friendtestuser').person
AddFriend.create!(:person => @profile, :friend => friend)
get :index, :profile => friend.identifier
assert_no_tag :tag => 'a', :content => 'Add friend'
end
+ should 'not display add friend button if user already friend' do
+ login_as(@profile.identifier)
+ friend = create_user('friendtestuser').person
+ @profile.add_friend(friend)
+ assert @profile.is_a_friend?(friend)
+ get :index, :profile => friend.identifier
+ assert_no_tag :tag => 'a', :content => 'Add friend'
+ end
+
should 'show message for disabled enterprise' do
login_as(@profile.identifier)
ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false)
diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb
index 881a43c..65aeb09 100644
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -465,4 +465,17 @@ class PersonTest < Test::Unit::TestCase
assert ! person.errors.invalid?(:custom_formation)
end
+ should 'identify when person is a friend' do
+ p1 = create_user('testuser1').person
+ p2 = create_user('testuser2').person
+ p1.add_friend(p2)
+ assert p1.is_a_friend?(p2)
+ end
+
+ should 'identify when person isnt a friend' do
+ p1 = create_user('testuser1').person
+ p2 = create_user('testuser2').person
+ assert !p1.is_a_friend?(p2)
+ end
+
end
--
libgit2 0.21.2