summaryrefslogtreecommitdiff
path: root/spec/views/projects/builds/show.html.haml_spec.rb
blob: 98b68e730e6fc17e216872f1e6010578bdd032bd (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
require 'spec_helper'

describe 'projects/builds/show', :view do
  let(:project) { create(:project) }
  let(:build) { create(:ci_build, pipeline: pipeline) }

  let(:pipeline) do
    create(:ci_pipeline, project: project, sha: project.commit.id)
  end

  before do
    assign(:build, build)
    assign(:project, project)

    allow(view).to receive(:can?).and_return(true)
  end

  describe 'environment info in build view' do
    context 'build with latest deployment' do
      let(:build) do
        create(:ci_build, :success, environment: 'staging')
      end

      before do
        create(:environment, name: 'staging')
        create(:deployment, deployable: build)
      end

      it 'shows deployment message' do
        expected_text = 'This build is the most recent deployment'

        render

        expect(rendered).to have_css(
          '.environment-information', text: expected_text)
      end
    end

    context 'build with outdated deployment' do
      let(:build) do
        create(:ci_build, :success, environment: 'staging', pipeline: pipeline)
      end

      let(:environment) do
        create(:environment, name: 'staging', project: project)
      end

      let!(:first_deployment) do
        create(:deployment, environment: environment, deployable: build)
      end

      let!(:second_deployment) do
        create(:deployment, environment: environment, deployable: build)
      end

      it 'shows deployment message' do
        expected_text = 'This build is an out-of-date deployment ' \
          "to staging. View the most recent deployment ##{first_deployment.id}"
        render

        expect(rendered).to have_css('.environment-information', text: expected_text)
      end
    end

    context 'build failed to deploy' do
      let(:build) { create(:ci_build, :failed, environment: 'staging') }
      let!(:environment) { create(:environment, name: 'staging') }
    end

    context 'build will deploy' do
      let(:build) { create(:ci_build, :running, environment: 'staging') }
      let!(:environment) { create(:environment, name: 'staging') }
    end

    context 'build that failed to deploy and environment has not been created' do
      let(:build) { create(:ci_build, :failed, environment: 'staging') }
    end

    context 'build that will deploy and environment has not been created' do
      let(:build) { create(:ci_build, :running, environment: 'staging') }
      let!(:environment) { create(:environment, name: 'staging') }
    end
  end

  context 'when build is running' do
    before do
      build.run!
      render
    end

    it 'does not show retry button' do
      expect(rendered).not_to have_link('Retry')
    end
  end

  context 'when build is not running' do
    before do
      build.success!
      render
    end

    it 'shows retry button' do
      expect(rendered).to have_link('Retry')
    end
  end

  describe 'commit title in sidebar' do
    let(:commit_title) { project.commit.title }

    it 'shows commit title and not show commit message' do
      render

      expect(rendered).to have_css('p.build-light-text.append-bottom-0',
        text: /\A\n#{Regexp.escape(commit_title)}\n\Z/)
    end
  end

  describe 'shows trigger variables in sidebar' do
    let(:trigger_request) { create(:ci_trigger_request_with_variables, pipeline: pipeline) }

    before do
      build.trigger_request = trigger_request
      render
    end

    it 'shows trigger variables in separate lines' do
      expect(rendered).to have_css('.js-build-variable', visible: false, text: 'TRIGGER_KEY_1')
      expect(rendered).to have_css('.js-build-variable', visible: false, text: 'TRIGGER_KEY_2')
      expect(rendered).to have_css('.js-build-value', visible: false, text: 'TRIGGER_VALUE_1')
      expect(rendered).to have_css('.js-build-value', visible: false, text: 'TRIGGER_VALUE_2')
    end
  end
end