show.html.haml_spec.rb 5.55 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'projects/jobs/show' do
4
  let(:project) { create(:project, :repository) }
5 6
  let(:build) { create(:ci_build, pipeline: pipeline) }

7
  let(:pipeline) do
8
    create(:ci_pipeline, project: project, sha: project.commit.id)
9
  end
10 11

  before do
12
    assign(:build, build.present)
13 14 15 16 17
    assign(:project, project)

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

Filipa Lacerda's avatar
Filipa Lacerda committed
18 19
  describe 'environment info in job view' do
    context 'job with latest deployment' do
20 21 22 23 24 25 26 27
      let(:build) do
        create(:ci_build, :success, environment: 'staging')
      end

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

      it 'shows deployment message' do
Filipa Lacerda's avatar
Filipa Lacerda committed
30
        expected_text = 'This job is the most recent deployment'
31 32 33 34
        render

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

Filipa Lacerda's avatar
Filipa Lacerda committed
38
    context 'job with outdated deployment' do
39 40 41
      let(:build) do
        create(:ci_build, :success, environment: 'staging', pipeline: pipeline)
      end
42

43 44 45 46
      let(:second_build) do
        create(:ci_build, :success, environment: 'staging', pipeline: pipeline)
      end

47 48 49
      let(:environment) do
        create(:environment, name: 'staging', project: project)
      end
50

51 52 53 54 55
      let!(:first_deployment) do
        create(:deployment, environment: environment, deployable: build)
      end

      let!(:second_deployment) do
56
        create(:deployment, environment: environment, deployable: second_build)
57 58 59
      end

      it 'shows deployment message' do
Filipa Lacerda's avatar
Filipa Lacerda committed
60
        expected_text = 'This job is an out-of-date deployment ' \
61
          "to staging.\nView the most recent deployment ##{second_deployment.iid}."
62 63 64
        render

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

Filipa Lacerda's avatar
Filipa Lacerda committed
68
    context 'job failed to deploy' do
69 70 71 72 73 74 75 76 77
      let(:build) do
        create(:ci_build, :failed, environment: 'staging', pipeline: pipeline)
      end

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

      it 'shows deployment message' do
Filipa Lacerda's avatar
Filipa Lacerda committed
78
        expected_text = 'The deployment of this job to staging did not succeed.'
79 80 81 82 83
        render

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

Filipa Lacerda's avatar
Filipa Lacerda committed
86
    context 'job will deploy' do
87 88 89 90
      let(:build) do
        create(:ci_build, :running, environment: 'staging', pipeline: pipeline)
      end

91
      context 'when environment exists' do
Kamil Trzcinski's avatar
Kamil Trzcinski committed
92 93 94 95 96
        let!(:environment) do
          create(:environment, name: 'staging', project: project)
        end

        it 'shows deployment message' do
Filipa Lacerda's avatar
Filipa Lacerda committed
97
          expected_text = 'This job is creating a deployment to staging'
Kamil Trzcinski's avatar
Kamil Trzcinski committed
98 99 100 101 102 103
          render

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

104
        context 'when it has deployment' do
Kamil Trzcinski's avatar
Kamil Trzcinski committed
105 106 107 108 109
          let!(:deployment) do
            create(:deployment, environment: environment)
          end

          it 'shows that deployment will be overwritten' do
Filipa Lacerda's avatar
Filipa Lacerda committed
110
            expected_text = 'This job is creating a deployment to staging'
Kamil Trzcinski's avatar
Kamil Trzcinski committed
111 112 113 114 115 116 117 118 119 120
            render

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

121
      context 'when environment does not exist' do
Kamil Trzcinski's avatar
Kamil Trzcinski committed
122
        it 'shows deployment message' do
Filipa Lacerda's avatar
Filipa Lacerda committed
123
          expected_text = 'This job is creating a deployment to staging'
Kamil Trzcinski's avatar
Kamil Trzcinski committed
124 125 126 127 128 129 130
          render

          expect(rendered).to have_css(
            '.environment-information', text: expected_text)
          expect(rendered).not_to have_css(
            '.environment-information', text: 'latest deployment')
        end
131
      end
132 133
    end

Filipa Lacerda's avatar
Filipa Lacerda committed
134
    context 'job that failed to deploy and environment has not been created' do
135 136 137 138 139 140 141 142 143
      let(:build) do
        create(:ci_build, :failed, environment: 'staging', pipeline: pipeline)
      end

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

      it 'shows deployment message' do
Filipa Lacerda's avatar
Filipa Lacerda committed
144
        expected_text = 'The deployment of this job to staging did not succeed'
145 146 147 148 149
        render

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

Filipa Lacerda's avatar
Filipa Lacerda committed
152
    context 'job that will deploy and environment has not been created' do
153 154 155 156 157 158 159 160 161
      let(:build) do
        create(:ci_build, :running, environment: 'staging', pipeline: pipeline)
      end

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

      it 'shows deployment message' do
Filipa Lacerda's avatar
Filipa Lacerda committed
162
        expected_text = 'This job is creating a deployment to staging'
163 164 165 166
        render

        expect(rendered).to have_css(
          '.environment-information', text: expected_text)
Kamil Trzcinski's avatar
Kamil Trzcinski committed
167 168
        expect(rendered).not_to have_css(
          '.environment-information', text: 'latest deployment')
169
      end
170 171 172
    end
  end

Filipa Lacerda's avatar
Filipa Lacerda committed
173
  context 'when job is running' do
174 175 176 177 178 179 180 181
    before do
      build.run!
      render
    end

    it 'does not show retry button' do
      expect(rendered).not_to have_link('Retry')
    end
Alex Sanford's avatar
Alex Sanford committed
182 183 184 185

    it 'does not show New issue button' do
      expect(rendered).not_to have_link('New issue')
    end
186 187
  end

188 189 190 191 192
  describe 'commit title in sidebar' do
    let(:commit_title) { project.commit.title }

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

194 195 196
      expect(rendered).to have_css('p.build-light-text.append-bottom-0',
        text: /\A\n#{Regexp.escape(commit_title)}\n\Z/)
    end
ubudzisz's avatar
ubudzisz committed
197
  end
198
end