summaryrefslogtreecommitdiff
path: root/spec/controllers/admin/groups_controller_spec.rb
blob: 509d8944e3a8d4f95a031aec9fed3f5aaa23ab31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# frozen_string_literal: true

require 'spec_helper'

describe Admin::GroupsController do
  let(:group) { create(:group) }
  let(:project) { create(:project, namespace: group) }
  let(:admin) { create(:admin) }

  before do
    sign_in(admin)
  end

  describe 'DELETE #destroy' do
    it 'schedules a group destroy' do
      Sidekiq::Testing.fake! do
        expect { delete :destroy, params: { id: project.group.path } }.to change(GroupDestroyWorker.jobs, :size).by(1)
      end
    end

    it 'redirects to the admin group path' do
      delete :destroy, params: { id: project.group.path }

      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, params: {
                             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 'can add unlimited members' do
      put :members_update, params: {
                             id: group,
                             user_ids: 1.upto(1000).to_a.join(','),
                             access_level: Gitlab::Access::GUEST
                           }

      expect(response).to set_flash.to 'Users were successfully added.'
      expect(response).to redirect_to(admin_group_path(group))
    end

    it 'adds no user to members' do
      put :members_update, params: {
                             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

    it 'updates the project_creation_level successfully' do
      expect do
        post :update, params: { id: group.to_param, group: { project_creation_level: ::Gitlab::Access::NO_ONE_PROJECT_ACCESS } }
      end.to change { group.reload.project_creation_level }.to(::Gitlab::Access::NO_ONE_PROJECT_ACCESS)
    end
  end
end