2018-09-06 15:20:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Projects::AutoDevops::DisableService, '#execute' do
|
2018-09-06 15:20:42 -04:00
|
|
|
let(:project) { create(:project, :repository, :auto_devops) }
|
|
|
|
let(:auto_devops) { project.auto_devops }
|
|
|
|
|
|
|
|
subject { described_class.new(project).execute }
|
|
|
|
|
|
|
|
context 'when Auto DevOps disabled at instance level' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(auto_devops_enabled: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Auto DevOps enabled at instance level' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(auto_devops_enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Auto DevOps explicitly enabled on project' do
|
|
|
|
before do
|
|
|
|
auto_devops.update!(enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Auto DevOps explicitly disabled on project' do
|
|
|
|
before do
|
|
|
|
auto_devops.update!(enabled: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Auto DevOps is implicitly enabled' do
|
|
|
|
before do
|
|
|
|
auto_devops.update!(enabled: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when is the first pipeline failure' do
|
|
|
|
before do
|
|
|
|
create(:ci_pipeline, :failed, :auto_devops_source, project: project)
|
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'disables Auto DevOps for project' do
|
2018-09-06 15:20:42 -04:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(auto_devops.enabled).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it is not the first pipeline failure' do
|
|
|
|
before do
|
|
|
|
create_list(:ci_pipeline, 2, :failed, :auto_devops_source, project: project)
|
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'explicitly disables Auto DevOps for project' do
|
2018-09-06 15:20:42 -04:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(auto_devops.reload.enabled).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an Auto DevOps pipeline has succeeded before' do
|
|
|
|
before do
|
|
|
|
create(:ci_pipeline, :success, :auto_devops_source, project: project)
|
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'does not disable Auto DevOps for project' do
|
2018-09-06 15:20:42 -04:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(auto_devops.reload.enabled).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project does not have an Auto DevOps record related' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:ci_pipeline, :failed, :auto_devops_source, project: project)
|
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'disables Auto DevOps for project' do
|
2018-09-06 15:20:42 -04:00
|
|
|
subject
|
|
|
|
auto_devops = project.reload.auto_devops
|
|
|
|
|
|
|
|
expect(auto_devops.enabled).to eq(false)
|
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'creates a ProjectAutoDevops record' do
|
2018-09-06 15:20:42 -04:00
|
|
|
expect { subject }.to change { ProjectAutoDevops.count }.from(0).to(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|