debian-mirror-gitlab/spec/controllers/admin/groups_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
3.6 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Admin::GroupsController do
2021-09-04 01:27:46 +05:30
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, namespace: group) }
let_it_be(:admin) { create(:admin) }
2016-09-13 17:45:13 +05:30
before do
sign_in(admin)
end
describe 'DELETE #destroy' do
it 'schedules a group destroy' do
Sidekiq::Testing.fake! do
2019-02-15 15:39:39 +05:30
expect { delete :destroy, params: { id: project.group.path } }.to change(GroupDestroyWorker.jobs, :size).by(1)
2016-09-13 17:45:13 +05:30
end
end
it 'redirects to the admin group path' do
2019-02-15 15:39:39 +05:30
delete :destroy, params: { id: project.group.path }
2016-09-13 17:45:13 +05:30
expect(response).to redirect_to(admin_groups_path)
end
end
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
describe 'POST #create' do
it 'creates group' do
expect do
post :create, params: { group: { path: 'test', name: 'test' } }
end.to change { Group.count }.by(1)
end
it 'creates namespace_settings for group' do
expect do
post :create, params: { group: { path: 'test', name: 'test' } }
end.to change { NamespaceSetting.count }.by(1)
end
2021-04-29 21:17:54 +05:30
it 'creates admin_note for group' do
expect do
post :create, params: { group: { path: 'test', name: 'test', admin_note_attributes: { note: 'test' } } }
end.to change { Namespace::AdminNote.count }.by(1)
end
2021-01-03 14:25:43 +05:30
end
2017-08-17 22:00:37 +05:30
describe 'PUT #members_update' do
2021-09-04 01:27:46 +05:30
let_it_be(:group_user) { create(:user) }
2017-08-17 22:00:37 +05:30
2021-09-04 01:27:46 +05:30
it 'adds user to members', :aggregate_failures, :snowplow do
2019-02-15 15:39:39 +05:30
put :members_update, params: {
id: group,
2022-07-16 23:28:13 +05:30
user_id: group_user.id,
2019-02-15 15:39:39 +05:30
access_level: Gitlab::Access::GUEST
}
2017-08-17 22:00:37 +05:30
2021-06-08 01:23:25 +05:30
expect(controller).to set_flash.to 'Users were successfully added.'
2017-08-17 22:00:37 +05:30
expect(response).to redirect_to(admin_group_path(group))
expect(group.users).to include group_user
2021-09-04 01:27:46 +05:30
expect_snowplow_event(
category: 'Members::CreateService',
action: 'create_member',
label: 'admin-group-page',
property: 'existing_user',
user: admin
)
2017-08-17 22:00:37 +05:30
end
2021-09-04 01:27:46 +05:30
it 'can add unlimited members', :aggregate_failures do
2019-02-15 15:39:39 +05:30
put :members_update, params: {
id: group,
2022-07-16 23:28:13 +05:30
user_id: 1.upto(1000).to_a.join(','),
2019-02-15 15:39:39 +05:30
access_level: Gitlab::Access::GUEST
}
2017-09-10 17:25:29 +05:30
2021-06-08 01:23:25 +05:30
expect(controller).to set_flash.to 'Users were successfully added.'
2017-09-10 17:25:29 +05:30
expect(response).to redirect_to(admin_group_path(group))
end
2021-09-04 01:27:46 +05:30
it 'adds no user to members', :aggregate_failures do
2019-02-15 15:39:39 +05:30
put :members_update, params: {
id: group,
2022-07-16 23:28:13 +05:30
user_id: '',
2019-02-15 15:39:39 +05:30
access_level: Gitlab::Access::GUEST
}
2017-08-17 22:00:37 +05:30
2021-06-08 01:23:25 +05:30
expect(controller).to set_flash.to 'No users specified.'
2017-08-17 22:00:37 +05:30
expect(response).to redirect_to(admin_group_path(group))
expect(group.users).not_to include group_user
end
2019-07-07 11:18:12 +05:30
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
2019-10-12 21:52:04 +05:30
it 'updates the subgroup_creation_level successfully' do
expect do
post :update,
params: { id: group.to_param,
group: { subgroup_creation_level: ::Gitlab::Access::OWNER_SUBGROUP_ACCESS } }
end.to change { group.reload.subgroup_creation_level }.to(::Gitlab::Access::OWNER_SUBGROUP_ACCESS)
end
2017-08-17 22:00:37 +05:30
end
2016-09-13 17:45:13 +05:30
end