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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ci::Deployments::DestroyService do
let_it_be(:project) { create(:project, :repository) }
let(:environment) { create(:environment, project: project) }
let(:commits) { project.repository.commits(nil, { limit: 3 }) }
let!(:deploy) do
create(
:deployment,
:success,
project: project,
environment: environment,
deployable: nil,
sha: commits[2].sha
)
end
let!(:running_deploy) do
create(
:deployment,
:running,
project: project,
environment: environment,
deployable: nil,
sha: commits[1].sha
)
end
let!(:old_deploy) do
create(
:deployment,
:success,
project: project,
environment: environment,
deployable: nil,
sha: commits[0].sha,
finished_at: 1.year.ago
)
end
let(:user) { project.first_owner }
subject { described_class.new(project, user) }
context 'when deleting a deployment' do
it 'delete is accepted for old deployment' do
expect(subject.execute(old_deploy)).to be_success
end
it 'does not delete a running deployment' do
response = subject.execute(running_deploy)
expect(response).to be_an_error
expect(response.message).to eq("Cannot destroy running deployment")
end
it 'does not delete the last deployment' do
response = subject.execute(deploy)
expect(response).to be_an_error
expect(response.message).to eq("Deployment currently deployed to environment")
end
end
end
|