diff --git a/app/views/blocks/profile_info_actions/community.rhtml b/app/views/blocks/profile_info_actions/community.rhtml
index 3343e8a..0b28cfa 100644
--- a/app/views/blocks/profile_info_actions/community.rhtml
+++ b/app/views/blocks/profile_info_actions/community.rhtml
@@ -1,5 +1,9 @@
- <% 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' %>
+ <% if logged_in? %>
+ <% if profile.members.include?(user) %>
+ - <%= link_to content_tag('span', _('Leave this community')), { :profile => user.identifier, :controller => 'memberships', :action => 'leave', :id => profile.id }, :class => 'button with-text icon-delete' %>
+ <% else %>
+ - <%= 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 %>
<% end %>
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index 4723a4b..7a58269 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -158,4 +158,25 @@ class ProfileControllerTest < Test::Unit::TestCase
assert_no_tag :tag => 'a', :child => { :tag => 'span', :content => 'Create a new community' }
end
+ should 'not show Leave 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_no_tag :tag => 'a', :content => 'Leave this community'
+ end
+
+ should 'show Leave 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_tag :tag => 'a', :content => 'Leave this community'
+ end
+
+ should 'not show Leave 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 => 'Leave this community'
+ end
+
end
--
libgit2 0.21.2