Commit 3f4b5a80 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'dz-refactor-admin-group-members' into 'master'

Refactor Admin::GroupsController#members_update method and add some specs

See merge request !10828
parents c6709c52 bae16440
......@@ -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
......
---
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment