Refactor Admin::GroupsController#members_update method and add some specs
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
9e4908afa6
commit
bae1644015
3 changed files with 34 additions and 2 deletions
|
@ -43,9 +43,13 @@ class Admin::GroupsController < Admin::ApplicationController
|
|||
end
|
||||
|
||||
def members_update
|
||||
@group.add_users(params[:user_ids].split(','), params[:access_level], current_user: current_user)
|
||||
status = Members::CreateService.new(@group, current_user, params).execute
|
||||
|
||||
redirect_to [:admin, @group], notice: 'Users were successfully added.'
|
||||
if status
|
||||
redirect_to [:admin, @group], notice: 'Users were successfully added.'
|
||||
else
|
||||
redirect_to [:admin, @group], alert: 'No users specified.'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Refactor Admin::GroupsController#members_update method and add some specs
|
||||
merge_request: 10735
|
||||
author:
|
|
@ -22,4 +22,28 @@ describe Admin::GroupsController do
|
|||
expect(response).to redirect_to(admin_groups_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #members_update' do
|
||||
let(:group_user) { create(:user) }
|
||||
|
||||
it 'adds user to members' do
|
||||
put :members_update, id: group,
|
||||
user_ids: group_user.id,
|
||||
access_level: Gitlab::Access::GUEST
|
||||
|
||||
expect(response).to set_flash.to 'Users were successfully added.'
|
||||
expect(response).to redirect_to(admin_group_path(group))
|
||||
expect(group.users).to include group_user
|
||||
end
|
||||
|
||||
it 'adds no user to members' do
|
||||
put :members_update, id: group,
|
||||
user_ids: '',
|
||||
access_level: Gitlab::Access::GUEST
|
||||
|
||||
expect(response).to set_flash.to 'No users specified.'
|
||||
expect(response).to redirect_to(admin_group_path(group))
|
||||
expect(group.users).not_to include group_user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue