Read about our upcoming Code of Conduct on this issue

projects_controller_spec.rb 26.8 KB
Newer Older
1
2
3
require('spec_helper')

describe ProjectsController do
4
5
  include ProjectForksHelper

6
7
  let(:project) { create(:project) }
  let(:public_project) { create(:project, :public) }
8
  let(:user) { create(:user) }
9
10
  let(:jpg) { fixture_file_upload('spec/fixtures/rails_sample.jpg', 'image/jpg') }
  let(:txt) { fixture_file_upload('spec/fixtures/doc_sample.txt', 'text/plain') }
11

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  describe 'GET new' do
    context 'with an authenticated user' do
      let(:group) { create(:group) }

      before do
        sign_in(user)
      end

      context 'when namespace_id param is present' do
        context 'when user has access to the namespace' do
          it 'renders the template' do
            group.add_owner(user)

            get :new, namespace_id: group.id

27
            expect(response).to have_gitlab_http_status(200)
28
29
30
31
32
33
34
35
            expect(response).to render_template('new')
          end
        end

        context 'when user does not have access to the namespace' do
          it 'responds with status 404' do
            get :new, namespace_id: group.id

36
            expect(response).to have_gitlab_http_status(404)
37
38
39
40
41
42
43
            expect(response).not_to render_template('new')
          end
        end
      end
    end
  end

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  describe 'GET index' do
    context 'as a user' do
      it 'redirects to root page' do
        sign_in(user)

        get :index

        expect(response).to redirect_to(root_path)
      end
    end

    context 'as a guest' do
      it 'redirects to Explore page' do
        get :index

        expect(response).to redirect_to(explore_root_path)
      end
    end
  end

64
  describe "GET show" do
65
    context "user not project member" do
66
67
68
      before do
        sign_in(user)
      end
69
70

      context "user does not have access to project" do
71
        let(:private_project) { create(:project, :private) }
72
73

        it "does not initialize notification setting" do
74
          get :show, namespace_id: private_project.namespace, id: private_project
75
76
77
78
79
80
81
          expect(assigns(:notification_setting)).to be_nil
        end
      end

      context "user has access to project" do
        context "and does not have notification setting" do
          it "initializes notification as disabled" do
82
            get :show, namespace_id: public_project.namespace, id: public_project
83
            expect(assigns(:notification_setting).level).to eq("global")
84
85
86
87
88
89
          end
        end

        context "and has notification setting" do
          before do
            setting = user.notification_settings_for(public_project)
90
            setting.level = :watch
91
92
93
94
            setting.save
          end

          it "shows current notification setting" do
95
            get :show, namespace_id: public_project.namespace, id: public_project
96
            expect(assigns(:notification_setting).level).to eq("watch")
97
98
99
          end
        end
      end
100
101
102
103
104

      describe "when project repository is disabled" do
        render_views

        before do
105
          project.add_developer(user)
106
107
108
109
          project.project_feature.update_attribute(:repository_access_level, ProjectFeature::DISABLED)
        end

        it 'shows wiki homepage' do
110
          get :show, namespace_id: project.namespace, id: project
111
112
113
114
115
116

          expect(response).to render_template('projects/_wiki')
        end

        it 'shows issues list page if wiki is disabled' do
          project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::DISABLED)
117
          create(:issue, project: project)
118

119
          get :show, namespace_id: project.namespace, id: project
120
121

          expect(response).to render_template('projects/issues/_issues')
122
          expect(assigns(:issuable_meta_data)).not_to be_nil
123
124
125
126
127
128
        end

        it 'shows customize workflow page if wiki and issues are disabled' do
          project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::DISABLED)
          project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED)

129
          get :show, namespace_id: project.namespace, id: project
130
131
132
133
134
135
136

          expect(response).to render_template("projects/_customize_workflow")
        end

        it 'shows activity if enabled by user' do
          user.update_attribute(:project_view, 'activity')

137
          get :show, namespace_id: project.namespace, id: project
138
139
140
141

          expect(response).to render_template("projects/_activity")
        end
      end
142
    end
143

144
    context 'when the storage is not available', :broken_storage do
145
146
      set(:project) { create(:project, :broken_storage) }

147
148
149
150
151
152
153
154
      before do
        project.add_developer(user)
        sign_in(user)
      end

      it 'renders a 503' do
        get :show, namespace_id: project.namespace, id: project

155
        expect(response).to have_gitlab_http_status(503)
156
157
158
      end
    end

159
160
161
    context "project with empty repo" do
      let(:empty_project) { create(:project_empty_repo, :public) }

162
163
164
      before do
        sign_in(user)
      end
165
166
167
168
169
170

      User.project_views.keys.each do |project_view|
        context "with #{project_view} view set" do
          before do
            user.update_attributes(project_view: project_view)

171
            get :show, namespace_id: empty_project.namespace, id: empty_project
172
173
174
175
176
177
178
179
180
          end

          it "renders the empty project view" do
            expect(response).to render_template('empty')
          end
        end
      end
    end

181
182
183
    context "project with broken repo" do
      let(:empty_project) { create(:project_broken_repo, :public) }

184
185
186
      before do
        sign_in(user)
      end
187
188
189
190
191
192

      User.project_views.keys.each do |project_view|
        context "with #{project_view} view set" do
          before do
            user.update_attributes(project_view: project_view)

193
            get :show, namespace_id: empty_project.namespace, id: empty_project
194
195
196
197
198
199
200
201
202
203
204
          end

          it "renders the empty project view" do
            allow(Project).to receive(:repo).and_raise(Gitlab::Git::Repository::NoRepository)

            expect(response).to render_template('projects/no_repo')
          end
        end
      end
    end

205
    context "rendering default project view" do
206
207
      let(:public_project) { create(:project, :public, :repository) }

208
      render_views
209

Douwe Maan's avatar
Douwe Maan committed
210
      it "renders the activity view" do
211
212
        allow(controller).to receive(:current_user).and_return(user)
        allow(user).to receive(:project_view).and_return('activity')
Douwe Maan's avatar
Douwe Maan committed
213

214
        get :show, namespace_id: public_project.namespace, id: public_project
215
216
217
        expect(response).to render_template('_activity')
      end

Douwe Maan's avatar
Douwe Maan committed
218
      it "renders the files view" do
219
220
        allow(controller).to receive(:current_user).and_return(user)
        allow(user).to receive(:project_view).and_return('files')
Douwe Maan's avatar
Douwe Maan committed
221

222
        get :show, namespace_id: public_project.namespace, id: public_project
223
224
        expect(response).to render_template('_files')
      end
225
226
227
228
229
230
231
232

      it "renders the readme view" do
        allow(controller).to receive(:current_user).and_return(user)
        allow(user).to receive(:project_view).and_return('readme')

        get :show, namespace_id: public_project.namespace, id: public_project
        expect(response).to render_template('_readme')
      end
233
    end
234

235
    context "when the url contains .atom" do
236
      let(:public_project_with_dot_atom) { build(:project, :public, name: 'my.atom', path: 'my.atom') }
237

238
      it 'expects an error creating the project' do
239
        expect(public_project_with_dot_atom).not_to be_valid
240
241
      end
    end
242
243
244

    context 'when the project is pending deletions' do
      it 'renders a 404 error' do
245
        project = create(:project, pending_delete: true)
246
247
        sign_in(user)

248
        get :show, namespace_id: project.namespace, id: project
249
250
251
252

        expect(response.status).to eq 404
      end
    end
253
254
255

    context "redirection from http://someproject.git" do
      it 'redirects to project page (format.html)' do
256
        project = create(:project, :public)
257

258
        get :show, namespace_id: project.namespace, id: project, format: :git
259

260
        expect(response).to have_gitlab_http_status(302)
261
262
263
        expect(response).to redirect_to(namespace_project_path)
      end
    end
264
265
266

    context 'when the project is forked and has a repository', :request_store do
      let(:public_project) { create(:project, :public, :repository) }
267
      let(:other_user) { create(:user) }
268
269
270
271
272

      render_views

      before do
        # View the project as a user that does not have any rights
273
        sign_in(other_user)
274
275
276
277
278

        fork_project(public_project)
      end

      it 'does not increase the number of queries when the project is forked' do
279
        expected_query = /#{public_project.fork_network.find_forks_in(other_user.namespace).to_sql}/
280
281

        expect { get(:show, namespace_id: public_project.namespace, id: public_project) }
282
          .not_to exceed_query_limit(1).for_query(expected_query)
283
284
      end
    end
285
  end
Stan Hu's avatar
Stan Hu committed
286

287
288
289
290
  describe "#update" do
    render_views

    let(:admin) { create(:admin) }
291
292
293
294

    before do
      sign_in(admin)
    end
295

Nick Thomas's avatar
Nick Thomas committed
296
297
298
    shared_examples_for 'updating a project' do
      context 'when only renaming a project path' do
        it "sets the repository to the right path after a rename" do
299
300
301
          original_repository_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
            project.repository.path
          end
302

Nick Thomas's avatar
Nick Thomas committed
303
304
305
          expect { update_project path: 'renamed_path' }
            .to change { project.reload.path }
          expect(project.path).to include 'renamed_path'
306

307
308
309
310
          assign_repository_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
            assigns(:repository).path
          end

Nick Thomas's avatar
Nick Thomas committed
311
          if project.hashed_storage?(:repository)
312
            expect(assign_repository_path).to eq(original_repository_path)
Nick Thomas's avatar
Nick Thomas committed
313
          else
314
            expect(assign_repository_path).to include(project.path)
Nick Thomas's avatar
Nick Thomas committed
315
316
317
318
          end

          expect(response).to have_gitlab_http_status(302)
        end
319
      end
320

Nick Thomas's avatar
Nick Thomas committed
321
322
323
324
325
326
327
328
329
330
      context 'when project has container repositories with tags' do
        before do
          stub_container_registry_config(enabled: true)
          stub_container_registry_tags(repository: /image/, tags: %w[rc1])
          create(:container_repository, project: project, name: :image)
        end

        it 'does not allow to rename the project' do
          expect { update_project path: 'renamed_path' }
            .not_to change { project.reload.path }
331

332
          expect(controller).to set_flash.now[:alert].to(/container registry tags/)
Nick Thomas's avatar
Nick Thomas committed
333
334
          expect(response).to have_gitlab_http_status(200)
        end
335
336
      end

Nick Thomas's avatar
Nick Thomas committed
337
338
339
340
341
342
      it 'updates Fast Forward Merge attributes' do
        controller.instance_variable_set(:@project, project)

        params = {
          merge_method: :ff
        }
343

Nick Thomas's avatar
Nick Thomas committed
344
345
346
347
        put :update,
            namespace_id: project.namespace,
            id: project.id,
            project: params
348

Nick Thomas's avatar
Nick Thomas committed
349
350
351
352
353
        expect(response).to have_gitlab_http_status(302)
        params.each do |param, value|
          expect(project.public_send(param)).to eq(value)
        end
      end
354

Nick Thomas's avatar
Nick Thomas committed
355
356
357
358
359
      def update_project(**parameters)
        put :update,
            namespace_id: project.namespace.path,
            id: project.path,
            project: parameters
360
361
362
      end
    end

Nick Thomas's avatar
Nick Thomas committed
363
364
365
366
367
368
369
370
371
372
    context 'hashed storage' do
      let(:project) { create(:project, :repository) }

      it_behaves_like 'updating a project'
    end

    context 'legacy storage' do
      let(:project) { create(:project, :repository, :legacy_storage) }

      it_behaves_like 'updating a project'
373
374
375
    end
  end

376
377
378
  describe '#transfer' do
    render_views

379
    let(:project) { create(:project, :repository) }
380
381
382
383
384
385
386
    let(:admin) { create(:admin) }
    let(:new_namespace) { create(:namespace) }

    it 'updates namespace' do
      sign_in(admin)

      put :transfer,
387
          namespace_id: project.namespace.path,
388
          new_namespace_id: new_namespace.id,
389
          id: project.path,
390
391
392
393
          format: :js

      project.reload

394
      expect(project.namespace).to eq(new_namespace)
395
      expect(response).to have_gitlab_http_status(200)
396
397
398
399
400
401
402
    end

    context 'when new namespace is empty' do
      it 'project namespace is not changed' do
        controller.instance_variable_set(:@project, project)
        sign_in(admin)

403
        old_namespace = project.namespace
404
405

        put :transfer,
406
            namespace_id: old_namespace.path,
407
            new_namespace_id: nil,
408
            id: project.path,
409
410
411
412
            format: :js

        project.reload

413
        expect(project.namespace).to eq(old_namespace)
414
        expect(response).to have_gitlab_http_status(200)
415
        expect(flash[:alert]).to eq 'Please select a new namespace for your project.'
416
417
418
419
      end
    end
  end

420
421
422
423
424
425
426
427
  describe "#destroy" do
    let(:admin) { create(:admin) }

    it "redirects to the dashboard" do
      controller.instance_variable_set(:@project, project)
      sign_in(admin)

      orig_id = project.id
428
      delete :destroy, namespace_id: project.namespace, id: project
429
430

      expect { Project.find(orig_id) }.to raise_error(ActiveRecord::RecordNotFound)
431
      expect(response).to have_gitlab_http_status(302)
432
433
      expect(response).to redirect_to(dashboard_projects_path)
    end
434

Katarzyna Kobierska's avatar
Katarzyna Kobierska committed
435
    context "when the project is forked" do
436
      let(:project)      { create(:project, :repository) }
437
      let(:forked_project) { fork_project(project, nil, repository: true) }
438
      let(:merge_request) do
439
        create(:merge_request,
440
          source_project: forked_project,
441
          target_project: project)
442
443
444
      end

      it "closes all related merge requests" do
445
446
        project.merge_requests << merge_request
        sign_in(admin)
447

448
        delete :destroy, namespace_id: forked_project.namespace, id: forked_project
449
450

        expect(merge_request.reload.state).to eq('closed')
451
452
      end
    end
453
454
  end

455
  describe 'PUT #new_issuable_address for issue' do
456
    subject do
457
      put :new_issuable_address,
458
        namespace_id: project.namespace,
459
460
        id: project,
        issuable_type: 'issue'
461
462
463
464
465
      user.reload
    end

    before do
      sign_in(user)
466
      project.add_developer(user)
467
468
469
470
      allow(Gitlab.config.incoming_email).to receive(:enabled).and_return(true)
    end

    it 'has http status 200' do
471
      expect(response).to have_gitlab_http_status(200)
472
473
474
475
476
477
478
    end

    it 'changes the user incoming email token' do
      expect { subject }.to change { user.incoming_email_token }
    end

    it 'changes projects new issue address' do
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
      expect { subject }.to change { project.new_issuable_address(user, 'issue') }
    end
  end

  describe 'PUT #new_issuable_address for merge request' do
    subject do
      put :new_issuable_address,
        namespace_id: project.namespace,
        id: project,
        issuable_type: 'merge_request'
      user.reload
    end

    before do
      sign_in(user)
494
      project.add_developer(user)
495
496
497
498
499
500
501
502
503
504
505
506
507
      allow(Gitlab.config.incoming_email).to receive(:enabled).and_return(true)
    end

    it 'has http status 200' do
      expect(response).to have_http_status(200)
    end

    it 'changes the user incoming email token' do
      expect { subject }.to change { user.incoming_email_token }
    end

    it 'changes projects new merge request address' do
      expect { subject }.to change { project.new_issuable_address(user, 'merge_request') }
508
509
510
    end
  end

Ciro Santilli's avatar
Ciro Santilli committed
511
  describe "POST #toggle_star" do
512
    it "toggles star if user is signed in" do
Ciro Santilli's avatar
Ciro Santilli committed
513
      sign_in(user)
514
      expect(user.starred?(public_project)).to be_falsey
Stan Hu's avatar
Stan Hu committed
515
      post(:toggle_star,
516
517
           namespace_id: public_project.namespace,
           id: public_project)
518
      expect(user.starred?(public_project)).to be_truthy
Stan Hu's avatar
Stan Hu committed
519
      post(:toggle_star,
520
521
           namespace_id: public_project.namespace,
           id: public_project)
522
      expect(user.starred?(public_project)).to be_falsey
Ciro Santilli's avatar
Ciro Santilli committed
523
524
525
    end

    it "does nothing if user is not signed in" do
Stan Hu's avatar
Stan Hu committed
526
      post(:toggle_star,
527
528
           namespace_id: project.namespace,
           id: public_project)
529
      expect(user.starred?(public_project)).to be_falsey
Stan Hu's avatar
Stan Hu committed
530
      post(:toggle_star,
531
532
           namespace_id: project.namespace,
           id: public_project)
533
      expect(user.starred?(public_project)).to be_falsey
Ciro Santilli's avatar
Ciro Santilli committed
534
535
    end
  end
536

Douwe Maan's avatar
Douwe Maan committed
537
  describe "DELETE remove_fork" do
538
539
540
541
542
543
    context 'when signed in' do
      before do
        sign_in(user)
      end

      context 'with forked project' do
544
        let(:forked_project) { fork_project(create(:project, :public), user) }
545

546
        it 'removes fork from project' do
547
          delete(:remove_fork,
548
549
              namespace_id: forked_project.namespace.to_param,
              id: forked_project.to_param, format: :js)
550

551
          expect(forked_project.reload.forked?).to be_falsey
Douwe Maan's avatar
Douwe Maan committed
552
          expect(flash[:notice]).to eq('The fork relationship has been removed.')
553
554
555
556
          expect(response).to render_template(:remove_fork)
        end
      end

557
      context 'when project not forked' do
558
        let(:unforked_project) { create(:project, namespace: user.namespace) }
559

560
        it 'does nothing if project was not forked' do
561
          delete(:remove_fork,
562
563
              namespace_id: unforked_project.namespace,
              id: unforked_project, format: :js)
564
565
566
567

          expect(flash[:notice]).to be_nil
          expect(response).to render_template(:remove_fork)
        end
568
569
570
571
      end
    end

    it "does nothing if user is not signed in" do
572
      delete(:remove_fork,
573
574
          namespace_id: project.namespace,
          id: project, format: :js)
575
      expect(response).to have_gitlab_http_status(401)
576
577
    end
  end
578
579

  describe "GET refs" do
580
    let(:public_project) { create(:project, :public, :repository) }
581

582
583
    it 'gets a list of branches and tags' do
      get :refs, namespace_id: public_project.namespace, id: public_project, sort: 'updated_desc'
584
585

      parsed_body = JSON.parse(response.body)
586
587
588
589
      expect(parsed_body['Branches']).to include('master')
      expect(parsed_body['Tags'].first).to eq('v1.1.0')
      expect(parsed_body['Tags'].last).to eq('v1.0.0')
      expect(parsed_body['Commits']).to be_nil
590
591
    end

592
    it "gets a list of branches, tags and commits" do
593
      get :refs, namespace_id: public_project.namespace, id: public_project, ref: "123456"
594
595
596
597
598
599

      parsed_body = JSON.parse(response.body)
      expect(parsed_body["Branches"]).to include("master")
      expect(parsed_body["Tags"]).to include("v1.0.0")
      expect(parsed_body["Commits"]).to include("123456")
    end
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615

    context "when preferred language is Japanese" do
      before do
        user.update!(preferred_language: 'ja')
        sign_in(user)
      end

      it "gets a list of branches, tags and commits" do
        get :refs, namespace_id: public_project.namespace, id: public_project, ref: "123456"

        parsed_body = JSON.parse(response.body)
        expect(parsed_body["Branches"]).to include("master")
        expect(parsed_body["Tags"]).to include("v1.0.0")
        expect(parsed_body["Commits"]).to include("123456")
      end
    end
616
  end
617
618

  describe 'POST #preview_markdown' do
619
    before do
620
      sign_in(user)
621
    end
622

623
    it 'renders json in a correct format' do
624
625
626
627
      post :preview_markdown, namespace_id: public_project.namespace, id: public_project, text: '*Markdown* text'

      expect(JSON.parse(response.body).keys).to match_array(%w(body references))
    end
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652

    context 'state filter on references' do
      let(:issue) { create(:issue, :closed, project: public_project) }
      let(:merge_request) { create(:merge_request, :closed, target_project: public_project) }

      it 'renders JSON body with state filter for issues' do
        post :preview_markdown, namespace_id: public_project.namespace,
                                id: public_project,
                                text: issue.to_reference

        json_response = JSON.parse(response.body)

        expect(json_response['body']).to match(/\##{issue.iid} \(closed\)/)
      end

      it 'renders JSON body with state filter for MRs' do
        post :preview_markdown, namespace_id: public_project.namespace,
                                id: public_project,
                                text: merge_request.to_reference

        json_response = JSON.parse(response.body)

        expect(json_response['body']).to match(/\!#{merge_request.iid} \(closed\)/)
      end
    end
653
  end
654

655
656
657
658
659
660
661
662
663
664
665
666
  describe '#ensure_canonical_path' do
    before do
      sign_in(user)
    end

    context 'for a GET request' do
      context 'when requesting the canonical path' do
        context "with exactly matching casing" do
          it "loads the project" do
            get :show, namespace_id: public_project.namespace, id: public_project

            expect(assigns(:project)).to eq(public_project)
667
            expect(response).to have_gitlab_http_status(200)
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
          end
        end

        context "with different casing" do
          it "redirects to the normalized path" do
            get :show, namespace_id: public_project.namespace, id: public_project.path.upcase

            expect(assigns(:project)).to eq(public_project)
            expect(response).to redirect_to("/#{public_project.full_path}")
            expect(controller).not_to set_flash[:notice]
          end
        end
      end

      context 'when requesting a redirected path' do
        let!(:redirect_route) { public_project.redirect_routes.create!(path: "foo/bar") }

        it 'redirects to the canonical path' do
          get :show, namespace_id: 'foo', id: 'bar'

          expect(response).to redirect_to(public_project)
          expect(controller).to set_flash[:notice].to(project_moved_message(redirect_route, public_project))
        end

        it 'redirects to the canonical path (testing non-show action)' do
          get :refs, namespace_id: 'foo', id: 'bar'

695
          expect(response).to redirect_to(refs_project_path(public_project))
696
697
698
699
700
701
702
703
704
705
          expect(controller).to set_flash[:notice].to(project_moved_message(redirect_route, public_project))
        end
      end
    end

    context 'for a POST request' do
      context 'when requesting the canonical path with different casing' do
        it 'does not 404' do
          post :toggle_star, namespace_id: public_project.namespace, id: public_project.path.upcase

706
          expect(response).not_to have_gitlab_http_status(404)
707
708
709
710
711
        end

        it 'does not redirect to the correct casing' do
          post :toggle_star, namespace_id: public_project.namespace, id: public_project.path.upcase

712
          expect(response).not_to have_gitlab_http_status(301)
713
714
715
716
717
718
719
720
721
        end
      end

      context 'when requesting a redirected path' do
        let!(:redirect_route) { public_project.redirect_routes.create!(path: "foo/bar") }

        it 'returns not found' do
          post :toggle_star, namespace_id: 'foo', id: 'bar'

722
          expect(response).to have_gitlab_http_status(404)
723
724
725
726
727
728
729
730
731
732
733
734
735
        end
      end
    end

    context 'for a DELETE request' do
      before do
        sign_in(create(:admin))
      end

      context 'when requesting the canonical path with different casing' do
        it 'does not 404' do
          delete :destroy, namespace_id: project.namespace, id: project.path.upcase

736
          expect(response).not_to have_gitlab_http_status(404)
737
738
739
740
741
        end

        it 'does not redirect to the correct casing' do
          delete :destroy, namespace_id: project.namespace, id: project.path.upcase

742
          expect(response).not_to have_gitlab_http_status(301)
743
744
745
746
747
748
749
750
751
        end
      end

      context 'when requesting a redirected path' do
        let!(:redirect_route) { project.redirect_routes.create!(path: "foo/bar") }

        it 'returns not found' do
          delete :destroy, namespace_id: 'foo', id: 'bar'

752
          expect(response).to have_gitlab_http_status(404)
753
754
755
756
757
        end
      end
    end
  end

758
759
760
761
762
763
764
765
766
767
768
  describe '#export' do
    before do
      sign_in(user)

      project.add_master(user)
    end

    context 'when project export is enabled' do
      it 'returns 302' do
        get :export, namespace_id: project.namespace, id: project

769
        expect(response).to have_gitlab_http_status(302)
770
771
772
773
774
775
776
777
778
779
780
      end
    end

    context 'when project export is disabled' do
      before do
        stub_application_setting(project_export_enabled?: false)
      end

      it 'returns 404' do
        get :export, namespace_id: project.namespace, id: project

781
        expect(response).to have_gitlab_http_status(404)
782
783
784
785
786
787
788
789
790
791
792
      end
    end
  end

  describe '#download_export' do
    before do
      sign_in(user)

      project.add_master(user)
    end

793
794
795
796
    context 'object storage disabled' do
      before do
        stub_feature_flags(import_export_object_storage: false)
      end
797

798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
      context 'when project export is enabled' do
        it 'returns 302' do
          get :download_export, namespace_id: project.namespace, id: project

          expect(response).to have_gitlab_http_status(302)
        end
      end

      context 'when project export is disabled' do
        before do
          stub_application_setting(project_export_enabled?: false)
        end

        it 'returns 404' do
          get :download_export, namespace_id: project.namespace, id: project

          expect(response).to have_gitlab_http_status(404)
        end
816
817
818
      end
    end

819
    context 'object storage enabled' do
820
      before do
821
        stub_feature_flags(import_export_object_storage: true)
822
823
      end

824
825
826
      context 'when project export is enabled' do
        it 'returns 302' do
          get :download_export, namespace_id: project.namespace, id: project
827

828
829
830
831
832
833
834
835
836
837
838
839
840
841
          expect(response).to have_gitlab_http_status(302)
        end
      end

      context 'when project export is disabled' do
        before do
          stub_application_setting(project_export_enabled?: false)
        end

        it 'returns 404' do
          get :download_export, namespace_id: project.namespace, id: project

          expect(response).to have_gitlab_http_status(404)
        end
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
      end
    end
  end

  describe '#remove_export' do
    before do
      sign_in(user)

      project.add_master(user)
    end

    context 'when project export is enabled' do
      it 'returns 302' do
        post :remove_export, namespace_id: project.namespace, id: project

857
        expect(response).to have_gitlab_http_status(302)
858
859
860
861
862
863
864
865
866
867
868
      end
    end

    context 'when project export is disabled' do
      before do
        stub_application_setting(project_export_enabled?: false)
      end

      it 'returns 404' do
        post :remove_export, namespace_id: project.namespace, id: project

869
        expect(response).to have_gitlab_http_status(404)
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
      end
    end
  end

  describe '#generate_new_export' do
    before do
      sign_in(user)

      project.add_master(user)
    end

    context 'when project export is enabled' do
      it 'returns 302' do
        post :generate_new_export, namespace_id: project.namespace, id: project

885
        expect(response).to have_gitlab_http_status(302)
886
887
888
889
890
891
892
893
894
895
896
      end
    end

    context 'when project export is disabled' do
      before do
        stub_application_setting(project_export_enabled?: false)
      end

      it 'returns 404' do
        post :generate_new_export, namespace_id: project.namespace, id: project

897
        expect(response).to have_gitlab_http_status(404)
898
899
900
901
      end
    end
  end

902
903
904
  def project_moved_message(redirect_route, project)
    "Project '#{redirect_route.path}' was moved to '#{project.full_path}'. Please update any links and bookmarks that may still have the old path."
  end
905
end