pipelines_spec.rb 10.1 KB
Newer Older
K
Kamil Trzcinski 已提交
1
require 'spec_helper'
2
require 'rails_helper'
K
Kamil Trzcinski 已提交
3

4
describe "Pipelines", feature: true, js: true do
K
Kamil Trzcinski 已提交
5
  include GitlabRoutingHelper
6
  include WaitForVueResource
K
Kamil Trzcinski 已提交
7 8 9 10

  let(:project) { create(:empty_project) }
  let(:user) { create(:user) }

K
Kamil Trzcinski 已提交
11 12 13 14 15
  before do
    login_as(user)
    project.team << [user, :developer]
  end

16 17 18
  describe 'GET /:project/pipelines', feature: true, js: true do
    include WaitForVueResource

19
    let(:project) { create(:project) }
R
Regis 已提交
20 21 22 23 24
    let!(:pipeline) do
      create(
        :ci_empty_pipeline,
        project: project,
        ref: 'master',
25 26
        status: 'running',
        sha: project.commit.id,
R
Regis 已提交
27 28
      )
    end
K
Kamil Trzcinski 已提交
29

30
    [:all, :running, :branches].each do |scope|
31
      context "displaying #{scope}" do
R
Regis 已提交
32 33 34 35 36
        before do
          visit namespace_project_pipelines_path(
            project.namespace,
            project, scope: scope
          )
37
          wait_for_vue_resource
R
Regis 已提交
38
        end
39

40 41 42
        it do
          expect(page).to have_content(pipeline.short_sha)
        end
43 44 45
      end
    end

46
    context 'anonymous access' do
R
Regis 已提交
47 48
      before do
        visit namespace_project_pipelines_path(project.namespace, project)
49
        wait_for_vue_resource
R
Regis 已提交
50
      end
51 52 53 54

      it { expect(page).to have_http_status(:success) }
    end

K
Kamil Trzcinski 已提交
55
    context 'cancelable pipeline' do
R
Regis 已提交
56 57 58
      let!(:build) do
        create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test')
      end
K
Kamil Trzcinski 已提交
59

60
      before do
61
        build.run
62
        visit namespace_project_pipelines_path(project.namespace, project)
63 64 65
        wait_for_vue_resource
      end

66 67 68
      it { expect(page).to have_link('Cancel') }

      it { expect(page).to have_selector('.ci-running') }
K
Kamil Trzcinski 已提交
69 70

      context 'when canceling' do
71 72 73 74
        before do
          wait_for_vue_resource
          click_link('Cancel')
        end
K
Kamil Trzcinski 已提交
75

76
        it { expect(page).not_to have_link('Cancel') }
77

78
        it { expect(page).to have_selector('.ci-canceled') }
K
Kamil Trzcinski 已提交
79 80 81 82
      end
    end

    context 'retryable pipelines' do
R
Regis 已提交
83 84 85
      let!(:build) do
        create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test')
      end
K
Kamil Trzcinski 已提交
86

87
      before do
88
        build.drop
89 90
        visit namespace_project_pipelines_path(project.namespace, project)
      end
K
Kamil Trzcinski 已提交
91 92 93 94 95

      it { expect(page).to have_link('Retry') }
      it { expect(page).to have_selector('.ci-failed') }

      context 'when retrying' do
96 97 98 99
        before do
          wait_for_vue_resource
          click_link('Retry')
        end
K
Kamil Trzcinski 已提交
100

101
        it { expect(page).not_to have_link('Retry') }
K
Kamil Trzcinski 已提交
102
        it { expect(page).to have_selector('.ci-running') }
K
Kamil Trzcinski 已提交
103 104 105
      end
    end

106
    context 'with manual actions' do
R
Regis 已提交
107 108 109 110 111 112 113 114 115 116
      let!(:manual) do
        create(
          :ci_build,
          :manual,
          pipeline: pipeline,
          name: 'manual build',
          stage: 'test',
          commands: 'test'
        )
      end
117

R
Regis 已提交
118 119 120
      before do
        visit namespace_project_pipelines_path(project.namespace, project)
      end
121

122 123 124 125
      it do
        wait_for_vue_resource
        expect(page).to have_link('Manual build')
      end
126 127

      context 'when playing' do
128 129 130 131
        before do
          wait_for_vue_resource
          click_link('Manual build')
        end
132

133 134 135 136
        it do
          wait_for_vue_resource
          expect(manual.reload).to be_pending
        end
137 138 139
      end
    end

140 141
    context 'for generic statuses' do
      context 'when running' do
R
Regis 已提交
142 143 144 145 146 147 148 149
        let!(:running) do
          create(
            :generic_commit_status,
            status: 'running',
            pipeline: pipeline,
            stage: 'test'
          )
        end
150

151 152 153
        before do
          visit namespace_project_pipelines_path(project.namespace, project)
        end
154

155 156
        it 'is cancelable' do
          expect(page).to have_link('Cancel')
157 158
        end

159
        it 'has pipeline running' do
160 161
          expect(page).to have_selector('.ci-running')
        end
162 163 164 165 166 167 168

        context 'when canceling' do
          before { click_link('Cancel') }

          it { expect(page).not_to have_link('Cancel') }
          it { expect(page).to have_selector('.ci-canceled') }
        end
169 170 171
      end

      context 'when failed' do
R
Regis 已提交
172 173 174 175 176 177 178 179
        let!(:status) do
          create(
            :generic_commit_status,
            :pending,
            pipeline: pipeline,
            stage: 'test'
          )
        end
180

181
        before do
182
          status.drop
183 184
          visit namespace_project_pipelines_path(project.namespace, project)
        end
185

186
        it 'is not retryable' do
K
Kamil Trzcinski 已提交
187
          expect(page).not_to have_link('Retry')
188 189
        end

190
        it 'has failed pipeline' do
191 192 193 194 195
          expect(page).to have_selector('.ci-failed')
        end
      end
    end

K
Kamil Trzcinski 已提交
196 197
    context 'downloadable pipelines' do
      context 'with artifacts' do
R
Regis 已提交
198 199 200 201 202 203 204 205 206 207
        let!(:with_artifacts) do
          create(
            :ci_build,
            :artifacts,
            :success,
            pipeline: pipeline,
            name: 'rspec tests',
            stage: 'test'
          )
        end
K
Kamil Trzcinski 已提交
208

R
Regis 已提交
209 210 211
        before do
          visit namespace_project_pipelines_path(project.namespace, project)
        end
K
Kamil Trzcinski 已提交
212

213 214 215 216 217 218 219 220 221
        it do
          wait_for_vue_resource
          expect(page).to have_selector('.build-artifacts')
        end

        it do
          wait_for_vue_resource
          expect(page).to have_link(with_artifacts.name)
        end
K
Kamil Trzcinski 已提交
222
      end
K
Kamil Trzcinski 已提交
223

224
      context 'with artifacts expired' do
R
Regis 已提交
225 226 227 228 229 230 231 232 233 234
        let!(:with_artifacts_expired) do
          create(
            :ci_build,
            :artifacts_expired,
            :success,
            pipeline: pipeline,
            name: 'rspec',
            stage: 'test'
          )
        end
235

R
Regis 已提交
236 237 238
        before do
          visit namespace_project_pipelines_path(project.namespace, project)
        end
239 240 241 242

        it { expect(page).not_to have_selector('.build-artifacts') }
      end

K
Kamil Trzcinski 已提交
243
      context 'without artifacts' do
R
Regis 已提交
244 245 246 247 248 249 250 251 252
        let!(:without_artifacts) do
          create(
            :ci_build,
            :success,
            pipeline: pipeline,
            name: 'rspec',
            stage: 'test'
          )
        end
K
Kamil Trzcinski 已提交
253

R
Regis 已提交
254 255 256
        before do
          visit namespace_project_pipelines_path(project.namespace, project)
        end
257

258
        it { expect(page).not_to have_selector('.build-artifacts') }
K
Kamil Trzcinski 已提交
259 260
      end
    end
K
Kamil Trzcinski 已提交
261 262
  end

K
Kamil Trzcinski 已提交
263
  describe 'GET /:project/pipelines/:id' do
A
Annabel Dunstone Gray 已提交
264
    let(:project) { create(:project) }
R
Regis 已提交
265 266 267 268 269 270
    let(:pipeline) do
      create(
        :ci_pipeline,
        project: project,
        ref: 'master',
        sha: project.commit.id
R
Regis 已提交
271
      )
R
Regis 已提交
272
    end
K
Kamil Trzcinski 已提交
273 274

    before do
R
Regis 已提交
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
      @success = create(
        :ci_build,
        :success,
        pipeline: pipeline,
        stage: 'build',
        name: 'build'
      )
      @failed = create(
        :ci_build,
        :failed,
        pipeline: pipeline,
        stage: 'test',
        name: 'test',
        commands: 'test'
      )
      @running = create(
        :ci_build,
        :running,
        pipeline: pipeline,
        stage: 'deploy',
        name: 'deploy'
      )
      @manual = create(
        :ci_build,
        :manual,
        pipeline: pipeline,
        stage: 'deploy',
        name: 'manual build'
      )
      @external = create(
        :generic_commit_status,
        status: 'success',
        pipeline: pipeline,
        name: 'jenkins',
        stage: 'external'
      )
K
Kamil Trzcinski 已提交
311 312
    end

R
Regis 已提交
313 314 315 316 317
    before do
      visit namespace_project_pipeline_path(
        project.namespace, project, pipeline
        )
    end
K
Kamil Trzcinski 已提交
318

319
    it 'shows a list of builds' do
320
      expect(page).to have_content('Test')
K
Kamil Trzcinski 已提交
321 322 323 324 325 326 327
      expect(page).to have_content(@success.id)
      expect(page).to have_content('Deploy')
      expect(page).to have_content(@failed.id)
      expect(page).to have_content(@running.id)
      expect(page).to have_content(@external.id)
      expect(page).to have_content('Retry failed')
      expect(page).to have_content('Cancel running')
328
      expect(page).to have_link('Play')
K
Kamil Trzcinski 已提交
329 330 331
    end

    context 'retrying builds' do
332
      it { expect(page).not_to have_content('retried') }
K
Kamil Trzcinski 已提交
333 334 335 336

      context 'when retrying' do
        before { click_on 'Retry failed' }

337
        it { expect(page).not_to have_content('Retry failed') }
338
        it { expect(page).to have_selector('.retried') }
K
Kamil Trzcinski 已提交
339 340 341 342
      end
    end

    context 'canceling builds' do
343
      it { expect(page).not_to have_selector('.ci-canceled') }
K
Kamil Trzcinski 已提交
344 345 346 347

      context 'when canceling' do
        before { click_on 'Cancel running' }

348
        it { expect(page).not_to have_content('Cancel running') }
K
Kamil Trzcinski 已提交
349 350 351
        it { expect(page).to have_selector('.ci-canceled') }
      end
    end
352 353

    context 'playing manual build' do
354 355 356 357 358
      before do
        within '.pipeline-holder' do
          click_link('Play')
        end
      end
359 360 361

      it { expect(@manual.reload).to be_pending }
    end
K
Kamil Trzcinski 已提交
362 363
  end

364
  describe 'POST /:project/pipelines', feature: true, js: true do
K
Kamil Trzcinski 已提交
365 366
    let(:project) { create(:project) }

R
Regis 已提交
367 368 369
    before do
      visit new_namespace_project_pipeline_path(project.namespace, project)
    end
K
Kamil Trzcinski 已提交
370 371

    context 'for valid commit' do
U
ubudzisz 已提交
372
      before { fill_in('pipeline[ref]', with: 'master') }
373 374

      context 'with gitlab-ci.yml' do
375
        before { stub_ci_pipeline_to_return_yaml_file }
376

R
Regis 已提交
377 378 379 380 381 382 383
        it do
          expect{
            click_on 'Create pipeline'
          }.to change{
            Ci::Pipeline.count
          }.by(1)
        end
K
Kamil Trzcinski 已提交
384
      end
K
Kamil Trzcinski 已提交
385

386 387 388 389 390
      context 'without gitlab-ci.yml' do
        before { click_on 'Create pipeline' }

        it { expect(page).to have_content('Missing .gitlab-ci.yml file') }
      end
K
Kamil Trzcinski 已提交
391 392 393 394
    end

    context 'for invalid commit' do
      before do
U
ubudzisz 已提交
395
        fill_in('pipeline[ref]', with: 'invalid-reference')
K
Kamil Trzcinski 已提交
396 397 398 399 400
        click_on 'Create pipeline'
      end

      it { expect(page).to have_content('Reference not found') }
    end
K
Kamil Trzcinski 已提交
401
  end
U
ubudzisz 已提交
402

403
  describe 'Create pipelines', feature: true, js: true do
U
ubudzisz 已提交
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
    let(:project) { create(:project) }

    before do
      visit new_namespace_project_pipeline_path(project.namespace, project)
    end

    describe 'new pipeline page' do
      it 'has field to add a new pipeline' do
        expect(page).to have_field('pipeline[ref]')
        expect(page).to have_content('Create for')
      end
    end

    describe 'find pipelines' do
      it 'shows filtered pipelines', js: true do
        fill_in('pipeline[ref]', with: 'fix')
        find('input#ref').native.send_keys(:keydown)

        within('.ui-autocomplete') do
          expect(page).to have_selector('li', text: 'fix')
        end
      end
    end
  end
K
Kamil Trzcinski 已提交
428
end