import_file_spec.rb 2.87 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'Import/Export - project import integration test', js: true do
4 5
  include Select2Helper

6
  let(:file) { File.join(Rails.root, 'spec', 'features', 'projects', 'import_export', 'test_project_export.tar.gz') }
Douwe Maan's avatar
Douwe Maan committed
7
  let(:export_path) { "#{Dir.tmpdir}/import_file_spec" }
James Lopez's avatar
James Lopez committed
8

9
  background do
10
    allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
11 12
  end

13
  after do
James Lopez's avatar
James Lopez committed
14 15 16
    FileUtils.rm_rf(export_path, secure: true)
  end

17 18 19 20
  context 'when selecting the namespace' do
    let(:user) { create(:admin) }
    let!(:namespace) { create(:namespace, name: "asd", owner: user) }

21
    before do
22
      gitlab_sign_in(user)
23
    end
James Lopez's avatar
James Lopez committed
24

25 26
    scenario 'user imports an exported project successfully' do
      visit new_project_path
27

28
      select2(namespace.id, from: '#project_namespace_id')
29 30
      fill_in :project_path, with: 'test-project-path', visible: true
      click_link 'GitLab export'
31

32
      expect(page).to have_content('Import an exported GitLab project')
33
      expect(URI.parse(current_url).query).to eq("namespace_id=#{namespace.id}&path=test-project-path")
34
      expect(Gitlab::ImportExport).to receive(:import_upload_path).with(filename: /\A\h{32}_test-project-path\z/).and_call_original
35

36
      attach_file('file', file)
37

38
      expect { click_on 'Import project' }.to change { Project.count }.from(0).to(1)
39

40
      project = Project.last
41 42 43
      expect(project).not_to be_nil
      expect(project.issues).not_to be_empty
      expect(project.merge_requests).not_to be_empty
44 45
      expect(project_hook_exists?(project)).to be true
      expect(wiki_exists?(project)).to be true
46 47
      expect(project.import_status).to eq('finished')
    end
48

49
    scenario 'invalid project' do
50
      project = create(:project, namespace: namespace)
James Lopez's avatar
James Lopez committed
51

52
      visit new_project_path
James Lopez's avatar
James Lopez committed
53

54
      select2(namespace.id, from: '#project_namespace_id')
55 56 57 58
      fill_in :project_path, with: project.name, visible: true
      click_link 'GitLab export'
      attach_file('file', file)
      click_on 'Import project'
James Lopez's avatar
James Lopez committed
59

60 61 62 63
      page.within('.flash-container') do
        expect(page).to have_content('Project could not be imported')
      end
    end
James Lopez's avatar
James Lopez committed
64 65
  end

66 67
  context 'when limited to the default user namespace' do
    let(:user) { create(:user) }
68
    before do
69
      gitlab_sign_in(user)
70
    end
James Lopez's avatar
James Lopez committed
71

72
    scenario 'passes correct namespace ID in the URL' do
73
      visit new_project_path
James Lopez's avatar
James Lopez committed
74

75
      fill_in :project_path, with: 'test-project-path', visible: true
James Lopez's avatar
James Lopez committed
76

77 78 79 80
      click_link 'GitLab export'

      expect(page).to have_content('GitLab project export')
      expect(URI.parse(current_url).query).to eq("namespace_id=#{user.namespace.id}&path=test-project-path")
James Lopez's avatar
James Lopez committed
81 82 83
    end
  end

84
  def wiki_exists?(project)
85
    wiki = ProjectWiki.new(project)
86
    File.exist?(wiki.repository.path_to_repo) && !wiki.repository.empty?
87
  end
88 89

  def project_hook_exists?(project)
90
    Gitlab::Git::Hook.new('post-receive', project).exists?
91
  end
92
end