diff --git a/app/views/blocks/profile_info_actions/community.rhtml b/app/views/blocks/profile_info_actions/community.rhtml
index 7ee47e4..3343e8a 100644
--- a/app/views/blocks/profile_info_actions/community.rhtml
+++ b/app/views/blocks/profile_info_actions/community.rhtml
@@ -1,5 +1,5 @@
- <% if logged_in? %>
+ <% if logged_in? && !profile.members.include?(user) %>
- <%= link_to content_tag('span', _('Join this community')), { :profile => user.identifier, :controller => 'memberships', :action => 'join', :id => profile.id }, :class => 'button with-text icon-add' %>
<% end %>
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index 18253d2..eba61b7 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -46,4 +46,26 @@ class ProfileControllerTest < Test::Unit::TestCase
assert_template 'members'
assert_kind_of Array, assigns(:members)
end
+
+ should 'show Join This Community button for non-member users' do
+ login_as(@profile.identifier)
+ community = Community.create!(:name => 'my test community')
+ get :index, :profile => community.identifier
+ assert_tag :tag => 'a', :content => 'Join this community'
+ end
+
+ should 'not show Join This Community button for member users' do
+ login_as(@profile.identifier)
+ community = Community.create!(:name => 'my test community')
+ community.add_member(@profile)
+ get :index, :profile => community.identifier
+ assert_no_tag :tag => 'a', :content => 'Join this community'
+ end
+
+ should 'not show Join This Community button for non-registered users' do
+ community = Community.create!(:name => 'my test community')
+ get :index, :profile => community.identifier
+ assert_no_tag :tag => 'a', :content => 'Join this community'
+ end
+
end
--
libgit2 0.21.2