summaryrefslogtreecommitdiff
path: root/spec/features/projects/import_export/namespace_export_file_spec.rb
blob: c1fccf4a40be12fcc07b896a5074cc48fc5f93c6 (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
require 'spec_helper'

feature 'Import/Export - Namespace export file cleanup', :js do
  let(:export_path) { Dir.mktmpdir('namespace_export_file_spec') }

  before do
    allow(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
  end

  after do
    FileUtils.rm_rf(export_path, secure: true)
  end

  shared_examples_for 'handling project exports on namespace change' do
    let!(:old_export_path) { project.export_path }

    before do
      sign_in(create(:admin))

      setup_export_project
    end

    context 'moving the namespace' do
      it 'removes the export file' do
        expect(File).to exist(old_export_path)

        project.namespace.update!(path: build(:namespace).path)

        expect(File).not_to exist(old_export_path)
      end
    end

    context 'deleting the namespace' do
      it 'removes the export file' do
        expect(File).to exist(old_export_path)

        project.namespace.destroy

        expect(File).not_to exist(old_export_path)
      end
    end
  end

  describe 'legacy storage' do
    let(:project) { create(:project) }

    it_behaves_like 'handling project exports on namespace change'
  end

  describe 'hashed storage' do
    let(:project) { create(:project, :hashed) }

    it_behaves_like 'handling project exports on namespace change'
  end

  def setup_export_project
    visit edit_project_path(project)

    expect(page).to have_content('Export project')

    find(:link, 'Export project').send_keys(:return)

    visit edit_project_path(project)

    expect(page).to have_content('Download export')
  end
end