Commit faeab49783ef9cbb54664def6b922b780051175c
Committed by
Antonio Terceiro
1 parent
7c655652
Exists in
master
and in
28 other branches
ActionItem1027: fix remove member of community
Showing
2 changed files
with
28 additions
and
6 deletions
Show diff stats
app/controllers/my_profile/profile_members_controller.rb
@@ -47,12 +47,16 @@ class ProfileMembersController < MyProfileController | @@ -47,12 +47,16 @@ class ProfileMembersController < MyProfileController | ||
47 | end | 47 | end |
48 | 48 | ||
49 | def unassociate | 49 | def unassociate |
50 | - @association = RoleAssignment.find(params[:id]) | ||
51 | - if @association.destroy | ||
52 | - flash[:notice] = 'Member succefully unassociated' | ||
53 | - else | ||
54 | - flash[:notice] = 'Failed to unassociate member' | 50 | + member = Person.find(params[:id]) |
51 | + associations = member.find_roles(profile) | ||
52 | + RoleAssignment.transaction do | ||
53 | + if associations.map(&:destroy) | ||
54 | + flash[:notice] = 'Member succefully unassociated' | ||
55 | + else | ||
56 | + flash[:notice] = 'Failed to unassociate member' | ||
57 | + end | ||
55 | end | 58 | end |
56 | - redirect_to :aciton => 'index' | 59 | + redirect_to :action => 'index' |
57 | end | 60 | end |
61 | + | ||
58 | end | 62 | end |
test/functional/profile_members_controller_test.rb
@@ -79,4 +79,22 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | @@ -79,4 +79,22 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | ||
79 | assert_includes roles, role2 | 79 | assert_includes roles, role2 |
80 | assert_not_includes roles, role1 | 80 | assert_not_includes roles, role1 |
81 | end | 81 | end |
82 | + | ||
83 | + should 'unassociate community member' do | ||
84 | + com = Community.create!(:identifier => 'test_community', :name => 'test community') | ||
85 | + admin = create_user_with_permission('admin_user', 'manage_memberships', com) | ||
86 | + member = create_user('test_member').person | ||
87 | + com.add_member(member) | ||
88 | + assert_includes com.members, member | ||
89 | + | ||
90 | + login_as :admin_user | ||
91 | + get :unassociate, :profile => com.identifier, :id => member | ||
92 | + | ||
93 | + assert_response :redirect | ||
94 | + assert_redirected_to :action => 'index' | ||
95 | + member.reload | ||
96 | + com.reload | ||
97 | + assert_not_includes com.members, member | ||
98 | + end | ||
99 | + | ||
82 | end | 100 | end |