pipelines_controller_spec.rb 14,3 КБ
Newer Older
gfyoung's avatar
gfyoung включено в состав коммита
1
2
# frozen_string_literal: true

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
3
4
5
require 'spec_helper'

describe Projects::PipelinesController do
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
6
7
  include ApiHelpers

Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
8
  set(:user) { create(:user) }
Bob Van Landuyt's avatar
Bob Van Landuyt включено в состав коммита
9
  let(:project) { create(:project, :public, :repository) }
Kamil Trzciński's avatar
Kamil Trzciński включено в состав коммита
10
  let(:feature) { ProjectFeature::ENABLED }
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
11
12

  before do
Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
13
14
    stub_not_protect_default_branch
    project.add_developer(user)
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
15
    project.project_feature.update(builds_access_level: feature)
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
16

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
17
18
19
    sign_in(user)
  end

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
20
21
  describe 'GET index.json' do
    before do
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
22
      %w(pending running success failed canceled).each_with_index do |status, index|
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
23
24
        create_pipeline(status, project.commit("HEAD~#{index}"))
      end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
25
26
    end

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
27
28
29
    context 'when using persisted stages', :request_store do
      before do
        stub_feature_flags(ci_pipeline_persisted_stages: true)
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
30
      end
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
31

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
32
      it 'returns serialized pipelines', :request_store do
Stan Hu's avatar
Stan Hu включено в состав коммита
33
34
        expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
35
36
37
        queries = ActiveRecord::QueryRecorder.new do
          get_pipelines_index_json
        end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
38

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
        expect(response).to have_gitlab_http_status(:ok)
        expect(response).to match_response_schema('pipeline')

        expect(json_response).to include('pipelines')
        expect(json_response['pipelines'].count).to eq 5
        expect(json_response['count']['all']).to eq '5'
        expect(json_response['count']['running']).to eq '1'
        expect(json_response['count']['pending']).to eq '1'
        expect(json_response['count']['finished']).to eq '3'

        json_response.dig('pipelines', 0, 'details', 'stages').tap do |stages|
          expect(stages.count).to eq 3
        end

        expect(queries.count).to be
      end
    end

Rémy Coutable's avatar
Rémy Coutable включено в состав коммита
57
    context 'when using legacy stages', :request_store do
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
58
59
60
61
      before do
        stub_feature_flags(ci_pipeline_persisted_stages: false)
      end

Yorick Peterse's avatar
Yorick Peterse включено в состав коммита
62
63
      it 'returns JSON with serialized pipelines' do
        get_pipelines_index_json
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
64
65
66
67
68
69
70
71
72
73
74
75
76
77

        expect(response).to have_gitlab_http_status(:ok)
        expect(response).to match_response_schema('pipeline')

        expect(json_response).to include('pipelines')
        expect(json_response['pipelines'].count).to eq 5
        expect(json_response['count']['all']).to eq '5'
        expect(json_response['count']['running']).to eq '1'
        expect(json_response['count']['pending']).to eq '1'
        expect(json_response['count']['finished']).to eq '3'

        json_response.dig('pipelines', 0, 'details', 'stages').tap do |stages|
          expect(stages.count).to eq 3
        end
Yorick Peterse's avatar
Yorick Peterse включено в состав коммита
78
79
80
81
82
83
      end

      it 'does not execute N+1 queries' do
        queries = ActiveRecord::QueryRecorder.new do
          get_pipelines_index_json
        end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
84

Yorick Peterse's avatar
Yorick Peterse включено в состав коммита
85
        expect(queries.count).to be <= 36
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
86
      end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
87
    end
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
88

Yorick Peterse's avatar
Yorick Peterse включено в состав коммита
89
    it 'does not include coverage data for the pipelines' do
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
90
      get_pipelines_index_json
Yorick Peterse's avatar
Yorick Peterse включено в состав коммита
91
92
93
94

      expect(json_response['pipelines'][0]).not_to include('coverage')
    end

Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
95
96
    context 'when performing gitaly calls', :request_store do
      it 'limits the Gitaly requests' do
Michael Kozono's avatar
Michael Kozono включено в состав коммита
97
98
99
100
101
        # Isolate from test preparation (Repository#exists? is also cached in RequestStore)
        RequestStore.end!
        RequestStore.clear!
        RequestStore.begin!

Stan Hu's avatar
Stan Hu включено в состав коммита
102
103
        expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
104
105
        expect { get_pipelines_index_json }
          .to change { Gitlab::GitalyClient.get_request_count }.by(2)
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
106
107
      end
    end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
108

Bob Van Landuyt's avatar
Bob Van Landuyt включено в состав коммита
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
    context 'when the project is private' do
      let(:project) { create(:project, :private, :repository) }

      it 'returns `not_found` when the user does not have access' do
        sign_in(create(:user))

        get_pipelines_index_json

        expect(response).to have_gitlab_http_status(:not_found)
      end

      it 'returns the pipelines when the user has access' do
        get_pipelines_index_json

        expect(json_response['pipelines'].size).to eq(5)
      end
    end

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
127
    def get_pipelines_index_json
blackst0ne's avatar
blackst0ne включено в состав коммита
128
129
130
131
      get :index, params: {
                    namespace_id: project.namespace,
                    project_id: project
                  },
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
132
133
134
                  format: :json
    end

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
135
136
137
138
139
140
141
142
143
144
    def create_pipeline(status, sha)
      pipeline = create(:ci_empty_pipeline, status: status,
                                            project: project,
                                            sha: sha)

      create_build(pipeline, 'build', 1, 'build')
      create_build(pipeline, 'test', 2, 'test')
      create_build(pipeline, 'deploy', 3, 'deploy')
    end

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
145
    def create_build(pipeline, stage, stage_idx, name)
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
146
147
      status = %w[created running pending success failed canceled].sample
      create(:ci_build, pipeline: pipeline, stage: stage, stage_idx: stage_idx, name: name, status: status)
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
148
    end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
149
150
  end

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
151
  describe 'GET show.json' do
Z.J. van de Weg's avatar
Z.J. van de Weg включено в состав коммита
152
    let(:pipeline) { create(:ci_pipeline_with_one_job, project: project) }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
153
154
155
156

    it 'returns the pipeline' do
      get_pipeline_json

Jacopo's avatar
Jacopo включено в состав коммита
157
      expect(response).to have_gitlab_http_status(:ok)
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
158
159
160
161
162
      expect(json_response).not_to be_an(Array)
      expect(json_response['id']).to be(pipeline.id)
      expect(json_response['details']).to have_key 'stages'
    end

Oswaldo Ferreira's avatar
Oswaldo Ferreira включено в состав коммита
163
    context 'when the pipeline has multiple stages and groups', :request_store do
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
164
165
166
167
168
169
170
171
      let(:project) { create(:project, :repository) }

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

Z.J. van de Weg's avatar
Z.J. van de Weg включено в состав коммита
172
173
174
175
176
177
178
      before do
        create_build('build', 0, 'build')
        create_build('test', 1, 'rspec 0')
        create_build('deploy', 2, 'production')
        create_build('post deploy', 3, 'pages 0')
      end

Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
179
      it 'does not perform N + 1 queries' do
Matija Čupić's avatar
Matija Čupić включено в состав коммита
180
181
182
        # Set up all required variables
        get_pipeline_json

Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
183
184
        control_count = ActiveRecord::QueryRecorder.new { get_pipeline_json }.count

Matija Čupić's avatar
Matija Čupić включено в состав коммита
185
186
187
188
189
190
191
        first_build = pipeline.builds.first
        first_build.tag_list << [:hello, :world]
        create(:deployment, deployable: first_build)

        second_build = pipeline.builds.second
        second_build.tag_list << [:docker, :ruby]
        create(:deployment, deployable: second_build)
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
192

Z.J. van de Weg's avatar
Z.J. van de Weg включено в состав коммита
193
        new_count = ActiveRecord::QueryRecorder.new { get_pipeline_json }.count
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
194

Matija Čupić's avatar
Matija Čupić включено в состав коммита
195
        expect(new_count).to be_within(1).of(control_count)
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
196
197
198
      end
    end

Kamil Trzciński's avatar
Kamil Trzciński включено в состав коммита
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
    context 'when builds are disabled' do
      let(:feature) { ProjectFeature::DISABLED }

      it 'users can not see internal pipelines' do
        get_pipeline_json

        expect(response).to have_gitlab_http_status(:not_found)
      end

      context 'when pipeline is external' do
        let(:pipeline) { create(:ci_pipeline, source: :external, project: project) }

        it 'users can see the external pipeline' do
          get_pipeline_json

          expect(response).to have_gitlab_http_status(:ok)
          expect(json_response['id']).to be(pipeline.id)
        end
      end
    end

Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
220
    def get_pipeline_json
blackst0ne's avatar
blackst0ne включено в состав коммита
221
      get :show, params: { namespace_id: project.namespace, project_id: project, id: pipeline }, format: :json
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
222
    end
Z.J. van de Weg's avatar
Z.J. van de Weg включено в состав коммита
223
224
225
226

    def create_build(stage, stage_idx, name)
      create(:ci_build, pipeline: pipeline, stage: stage, stage_idx: stage_idx, name: name)
    end
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
227
228
  end

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
229
  describe 'GET stages.json' do
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
230
231
    let(:pipeline) { create(:ci_pipeline, project: project) }

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
232
233
    context 'when accessing existing stage' do
      before do
Steve Azzopardi's avatar
Steve Azzopardi включено в состав коммита
234
        create(:ci_build, :retried, :failed, pipeline: pipeline, stage: 'build')
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
235
        create(:ci_build, pipeline: pipeline, stage: 'build')
Steve Azzopardi's avatar
Steve Azzopardi включено в состав коммита
236
237
238
239
240
241
      end

      context 'without retried' do
        before do
          get_stage('build')
        end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
242

Steve Azzopardi's avatar
Steve Azzopardi включено в состав коммита
243
244
245
246
247
248
        it 'returns pipeline jobs without the retried builds' do
          expect(response).to have_gitlab_http_status(:ok)
          expect(response).to match_response_schema('pipeline_stage')
          expect(json_response['latest_statuses'].length).to eq 1
          expect(json_response).not_to have_key('retried')
        end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
249
250
      end

Steve Azzopardi's avatar
Steve Azzopardi включено в состав коммита
251
252
253
254
255
256
257
258
259
260
261
      context 'with retried' do
        before do
          get_stage('build', retried: true)
        end

        it 'returns pipelines jobs with the retried builds' do
          expect(response).to have_gitlab_http_status(:ok)
          expect(response).to match_response_schema('pipeline_stage')
          expect(json_response['latest_statuses'].length).to eq 1
          expect(json_response['retried'].length).to eq 1
        end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
262
263
264
265
266
267
268
269
      end
    end

    context 'when accessing unknown stage' do
      before do
        get_stage('test')
      end

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
270
      it 'responds with not found' do
Jacopo's avatar
Jacopo включено в состав коммита
271
        expect(response).to have_gitlab_http_status(:not_found)
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
272
      end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
273
274
    end

Steve Azzopardi's avatar
Steve Azzopardi включено в состав коммита
275
    def get_stage(name, params = {})
blackst0ne's avatar
blackst0ne включено в состав коммита
276
277
278
279
280
281
282
283
      get :stage, params: {
**params.merge(
  namespace_id: project.namespace,
  project_id: project,
  id: pipeline.id,
  stage: name,
  format: :json)
}
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
284
    end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
285
  end
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
286

Kamil Trzciński's avatar
Kamil Trzciński включено в состав коммита
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
  describe 'GET stages_ajax.json' do
    let(:pipeline) { create(:ci_pipeline, project: project) }

    context 'when accessing existing stage' do
      before do
        create(:ci_build, pipeline: pipeline, stage: 'build')

        get_stage_ajax('build')
      end

      it 'returns html source for stage dropdown' do
        expect(response).to have_gitlab_http_status(:ok)
        expect(response).to render_template('projects/pipelines/_stage')
        expect(json_response).to include('html')
      end
    end

    context 'when accessing unknown stage' do
      before do
        get_stage_ajax('test')
      end

      it 'responds with not found' do
        expect(response).to have_gitlab_http_status(:not_found)
      end
    end

    def get_stage_ajax(name)
blackst0ne's avatar
blackst0ne включено в состав коммита
315
316
317
318
319
320
      get :stage_ajax, params: {
                         namespace_id: project.namespace,
                         project_id: project,
                         id: pipeline.id,
                         stage: name
                       },
Matija Čupić's avatar
Matija Čupić включено в состав коммита
321
                       format: :json
Kamil Trzciński's avatar
Kamil Trzciński включено в состав коммита
322
323
324
    end
  end

Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
325
  describe 'GET status.json' do
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
326
327
    let(:pipeline) { create(:ci_pipeline, project: project) }
    let(:status) { pipeline.detailed_status(double('user')) }
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
328

Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
329
    before do
blackst0ne's avatar
blackst0ne включено в состав коммита
330
331
332
333
334
      get :status, params: {
                     namespace_id: project.namespace,
                     project_id: project,
                     id: pipeline.id
                   },
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
335
336
                   format: :json
    end
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
337

Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
338
    it 'return a detailed pipeline status in json' do
Jacopo's avatar
Jacopo включено в состав коммита
339
      expect(response).to have_gitlab_http_status(:ok)
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
340
341
342
      expect(json_response['text']).to eq status.text
      expect(json_response['label']).to eq status.label
      expect(json_response['icon']).to eq status.icon
Alexis Reigel's avatar
Alexis Reigel включено в состав коммита
343
      expect(json_response['favicon']).to match_asset_path("/assets/ci_favicons/#{status.favicon}.png")
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
344
345
    end
  end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
346
347
348
349
350
351

  describe 'POST retry.json' do
    let!(:pipeline) { create(:ci_pipeline, :failed, project: project) }
    let!(:build) { create(:ci_build, :failed, pipeline: pipeline) }

    before do
blackst0ne's avatar
blackst0ne включено в состав коммита
352
353
354
355
356
      post :retry, params: {
                     namespace_id: project.namespace,
                     project_id: project,
                     id: pipeline.id
                   },
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
357
358
359
                   format: :json
    end

Kamil Trzciński's avatar
Kamil Trzciński включено в состав коммита
360
361
362
    it 'retries a pipeline without returning any content' do
      expect(response).to have_gitlab_http_status(:no_content)
      expect(build.reload).to be_retried
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
363
364
365
    end

    context 'when builds are disabled' do
Kamil Trzciński's avatar
Kamil Trzciński включено в состав коммита
366
367
      let(:feature) { ProjectFeature::DISABLED }

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
368
      it 'fails to retry pipeline' do
Jacopo's avatar
Jacopo включено в состав коммита
369
        expect(response).to have_gitlab_http_status(:not_found)
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
370
      end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
371
372
373
374
375
376
    end
  end

  describe 'POST cancel.json' do
    let!(:pipeline) { create(:ci_pipeline, project: project) }
    let!(:build) { create(:ci_build, :running, pipeline: pipeline) }
Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
377

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
378
    before do
blackst0ne's avatar
blackst0ne включено в состав коммита
379
380
381
382
383
      post :cancel, params: {
                      namespace_id: project.namespace,
                      project_id: project,
                      id: pipeline.id
                    },
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
384
385
386
                    format: :json
    end

Kamil Trzciński's avatar
Kamil Trzciński включено в состав коммита
387
388
389
    it 'cancels a pipeline without returning any content' do
      expect(response).to have_gitlab_http_status(:no_content)
      expect(pipeline.reload).to be_canceled
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
390
391
392
    end

    context 'when builds are disabled' do
Kamil Trzciński's avatar
Kamil Trzciński включено в состав коммита
393
394
      let(:feature) { ProjectFeature::DISABLED }

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
395
      it 'fails to retry pipeline' do
Jacopo's avatar
Jacopo включено в состав коммита
396
        expect(response).to have_gitlab_http_status(:not_found)
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
397
      end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
398
399
    end
  end
Alex Ives's avatar
Alex Ives включено в состав коммита
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464

  describe 'GET latest' do
    let(:branch_main) { project.repository.branches[0] }
    let(:branch_secondary) { project.repository.branches[1] }

    let!(:pipeline_master) do
      create(:ci_pipeline,
             ref: branch_main.name,
             sha: branch_main.target,
             project: project)
    end

    let!(:pipeline_secondary) do
      create(:ci_pipeline,
             ref: branch_secondary.name,
             sha: branch_secondary.target,
             project: project)
    end

    before do
      project.change_head(branch_main.name)
      project.reload_default_branch
    end

    context 'no ref provided' do
      it 'shows latest pipeline for the default project branch' do
        get :show, params: { namespace_id: project.namespace, project_id: project, latest: true, ref: nil }

        expect(response).to have_gitlab_http_status(200)
        expect(assigns(:pipeline)).to have_attributes(id: pipeline_master.id)
      end
    end

    context 'ref provided' do
      before do
        create(:ci_pipeline, ref: 'master', project: project)
      end

      it 'shows the latest pipeline for the provided ref' do
        get :show, params: { namespace_id: project.namespace, project_id: project, latest: true, ref: branch_secondary.name }

        expect(response).to have_gitlab_http_status(200)
        expect(assigns(:pipeline)).to have_attributes(id: pipeline_secondary.id)
      end

      context 'newer pipeline exists for older sha' do
        before do
          create(:ci_pipeline, ref: branch_secondary.name, sha: project.commit(branch_secondary.name).parent, project: project)
        end

        it 'shows the provided ref with the last sha/pipeline combo' do
          get :show, params: { namespace_id: project.namespace, project_id: project, latest: true, ref: branch_secondary.name }

          expect(response).to have_gitlab_http_status(200)
          expect(assigns(:pipeline)).to have_attributes(id: pipeline_secondary.id)
        end
      end
    end

    it 'renders a 404 if no pipeline is found for the ref' do
      get :show, params: { namespace_id: project.namespace, project_id: project, ref: 'no-branch' }

      expect(response).to have_gitlab_http_status(404)
    end
  end
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
465
end