debian-mirror-gitlab/spec/controllers/groups/settings/ci_cd_controller_spec.rb

226 lines
5.5 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
describe Groups::Settings::CiCdController do
2019-07-07 11:18:12 +05:30
include ExternalAuthorizationServiceHelpers
2017-09-10 17:25:29 +05:30
let(:group) { create(:group) }
let(:user) { create(:user) }
before do
sign_in(user)
end
describe 'GET #show' do
2019-01-03 12:48:30 +05:30
context 'when user is owner' do
before do
group.add_owner(user)
end
2017-09-10 17:25:29 +05:30
2019-01-03 12:48:30 +05:30
it 'renders show with 200 status code' do
2019-02-15 15:39:39 +05:30
get :show, params: { group_id: group }
2019-01-03 12:48:30 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-01-03 12:48:30 +05:30
expect(response).to render_template(:show)
end
end
context 'when user is not owner' do
before do
group.add_maintainer(user)
end
it 'renders a 404' do
2019-02-15 15:39:39 +05:30
get :show, params: { group_id: group }
2019-01-03 12:48:30 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2019-01-03 12:48:30 +05:30
end
2017-09-10 17:25:29 +05:30
end
2019-07-07 11:18:12 +05:30
context 'external authorization' do
before do
enable_external_authorization_service_check
group.add_owner(user)
end
it 'renders show with 200 status code' do
get :show, params: { group_id: group }
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-07-07 11:18:12 +05:30
end
end
2017-09-10 17:25:29 +05:30
end
2018-12-05 23:21:45 +05:30
describe 'PUT #reset_registration_token' do
2019-02-15 15:39:39 +05:30
subject { put :reset_registration_token, params: { group_id: group } }
2018-12-05 23:21:45 +05:30
2019-01-03 12:48:30 +05:30
context 'when user is owner' do
before do
group.add_owner(user)
end
it 'resets runner registration token' do
expect { subject }.to change { group.reload.runners_token }
end
it 'redirects the user to admin runners page' do
subject
expect(response).to redirect_to(group_settings_ci_cd_path)
end
2018-12-05 23:21:45 +05:30
end
2019-01-03 12:48:30 +05:30
context 'when user is not owner' do
before do
group.add_maintainer(user)
end
it 'renders a 404' do
subject
2018-12-05 23:21:45 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2019-01-03 12:48:30 +05:30
end
2018-12-05 23:21:45 +05:30
end
end
2019-07-07 11:18:12 +05:30
describe 'PATCH #update_auto_devops' do
let(:auto_devops_param) { '1' }
subject do
patch :update_auto_devops, params: {
group_id: group,
group: { auto_devops_enabled: auto_devops_param }
}
end
context 'when user does not have enough permission' do
before do
group.add_maintainer(user)
end
2020-03-13 15:44:24 +05:30
it { is_expected.to have_gitlab_http_status(:not_found) }
2019-07-07 11:18:12 +05:30
end
context 'when user has enough privileges' do
before do
group.add_owner(user)
end
it { is_expected.to redirect_to(group_settings_ci_cd_path) }
context 'when service execution went wrong' do
before do
allow_any_instance_of(Groups::AutoDevopsService).to receive(:execute).and_return(false)
allow_any_instance_of(Group).to receive_message_chain(:errors, :full_messages)
.and_return(['Error 1'])
subject
end
it 'returns a flash alert' do
expect(response).to set_flash[:alert]
.to eq("There was a problem updating Auto DevOps pipeline: [\"Error 1\"].")
end
end
context 'when service execution was successful' do
it 'returns a flash notice' do
subject
expect(response).to set_flash[:notice]
.to eq('Auto DevOps pipeline was updated for the group')
end
end
context 'when changing auto devops value' do
before do
subject
group.reload
end
context 'when explicitly enabling auto devops' do
it 'updates group attribute' do
expect(group.auto_devops_enabled).to eq(true)
end
end
context 'when explicitly disabling auto devops' do
let(:auto_devops_param) { '0' }
it 'updates group attribute' do
expect(group.auto_devops_enabled).to eq(false)
end
end
end
end
end
2019-12-21 20:55:43 +05:30
describe 'PATCH #update' do
subject do
patch :update, params: {
group_id: group,
group: { max_artifacts_size: 10 }
}
end
context 'when user is not an admin' do
before do
group.add_owner(user)
end
2020-03-13 15:44:24 +05:30
it { is_expected.to have_gitlab_http_status(:not_found) }
2019-12-21 20:55:43 +05:30
end
context 'when user is an admin' do
let(:user) { create(:admin) }
before do
group.add_owner(user)
end
it { is_expected.to redirect_to(group_settings_ci_cd_path) }
context 'when service execution went wrong' do
let(:update_service) { double }
before do
allow(Groups::UpdateService).to receive(:new).and_return(update_service)
allow(update_service).to receive(:execute).and_return(false)
allow_any_instance_of(Group).to receive_message_chain(:errors, :full_messages)
.and_return(['Error 1'])
subject
end
it 'returns a flash alert' do
expect(response).to set_flash[:alert]
.to eq("There was a problem updating the pipeline settings: [\"Error 1\"].")
end
end
context 'when service execution was successful' do
it 'returns a flash notice' do
subject
expect(response).to set_flash[:notice]
.to eq('Pipeline settings was updated for the group')
end
end
end
end
2020-04-08 14:13:33 +05:30
describe 'POST create_deploy_token' do
it_behaves_like 'a created deploy token' do
let(:entity) { group }
let(:create_entity_params) { { group_id: group } }
let(:deploy_token_type) { DeployToken.deploy_token_types[:group_type] }
before do
entity.add_owner(user)
end
end
end
2017-09-10 17:25:29 +05:30
end