summaryrefslogtreecommitdiff
path: root/spec/services/deployments/update_service_spec.rb
blob: d3840189ba4f555b83a220a8f8e0a8432b975a0a (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Deployments::UpdateService do
  let(:deploy) { create(:deployment) }

  describe '#execute' do
    it 'can update the status to running' do
      expect(described_class.new(deploy, status: 'running').execute)
        .to be_truthy

      expect(deploy).to be_running
    end

    it 'can update the status to success' do
      expect(described_class.new(deploy, status: 'success').execute)
        .to be_truthy

      expect(deploy).to be_success
    end

    it 'can update the status to failed' do
      expect(described_class.new(deploy, status: 'failed').execute)
        .to be_truthy

      expect(deploy).to be_failed
    end

    it 'can update the status to canceled' do
      expect(described_class.new(deploy, status: 'canceled').execute)
        .to be_truthy

      expect(deploy).to be_canceled
    end

    it 'does not change the state if the status is invalid' do
      expect(described_class.new(deploy, status: 'kittens').execute)
        .to be_falsy

      expect(deploy).to be_created
    end

    it 'links merge requests when changing the status to success', :sidekiq_inline do
      mr = create(
        :merge_request,
        :merged,
        target_project: deploy.project,
        source_project: deploy.project,
        target_branch: 'master',
        source_branch: 'foo'
      )

      described_class.new(deploy, status: 'success').execute

      expect(deploy.merge_requests).to eq([mr])
    end
  end
end