debian-mirror-gitlab/spec/features/projects/import_export/import_file_spec.rb

109 lines
3.7 KiB
Ruby
Raw Normal View History

2016-06-22 15:30:34 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
feature 'Import/Export - project import integration test', js: true do
2016-06-22 15:30:34 +05:30
include Select2Helper
2017-09-10 17:25:29 +05:30
let(:gitlab_shell) { Gitlab::Shell.new }
let(:repository_storage_path) { Gitlab.config.repositories.storages['default']['path'] }
let(:user) { create(:user) }
2016-06-22 15:30:34 +05:30
let(:file) { File.join(Rails.root, 'spec', 'features', 'projects', 'import_export', 'test_project_export.tar.gz') }
2017-08-17 22:00:37 +05:30
let(:export_path) { "#{Dir.tmpdir}/import_file_spec" }
2016-06-22 15:30:34 +05:30
background do
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
2017-09-10 17:25:29 +05:30
gitlab_sign_in(user)
2016-06-22 15:30:34 +05:30
end
after(:each) do
FileUtils.rm_rf(export_path, secure: true)
2017-09-10 17:25:29 +05:30
gitlab_shell.remove_repository(repository_storage_path, 'asd/test-project-path')
gitlab_shell.remove_repository(repository_storage_path, 'asd/test-project-path.wiki')
2016-06-22 15:30:34 +05:30
end
2016-11-03 12:29:30 +05:30
context 'when selecting the namespace' do
let(:user) { create(:admin) }
let!(:namespace) { create(:namespace, name: "asd", owner: user) }
2017-09-10 17:25:29 +05:30
context 'prefilled the path' do
scenario 'user imports an exported project successfully' do
visit new_project_path
2016-06-22 15:30:34 +05:30
2017-09-10 17:25:29 +05:30
select2(namespace.id, from: '#project_namespace_id')
fill_in :project_path, with: 'test-project-path', visible: true
click_link 'GitLab export'
2016-06-22 15:30:34 +05:30
2017-09-10 17:25:29 +05:30
expect(page).to have_content('Import an exported GitLab project')
expect(URI.parse(current_url).query).to eq("namespace_id=#{namespace.id}&path=test-project-path")
expect(Gitlab::ImportExport).to receive(:import_upload_path).with(filename: /\A[0-9a-f]{32}_test_project_export\.tar\.gz\z/).and_call_original
2016-06-22 15:30:34 +05:30
2017-09-10 17:25:29 +05:30
attach_file('file', file)
2016-06-22 15:30:34 +05:30
2017-09-10 17:25:29 +05:30
expect { click_on 'Import project' }.to change { Project.count }.by(1)
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
project = Project.last
expect(project).not_to be_nil
expect(project.issues).not_to be_empty
expect(project.merge_requests).not_to be_empty
expect(project_hook_exists?(project)).to be true
expect(wiki_exists?(project)).to be true
expect(project.import_status).to eq('finished')
end
2016-09-13 17:45:13 +05:30
end
2016-06-22 15:30:34 +05:30
2017-09-10 17:25:29 +05:30
context 'path is not prefilled' do
scenario 'user imports an exported project successfully' do
visit new_project_path
click_link 'GitLab export'
2016-08-24 12:49:21 +05:30
2017-09-10 17:25:29 +05:30
fill_in :path, with: 'test-project-path', visible: true
attach_file('file', file)
2016-08-24 12:49:21 +05:30
2017-09-10 17:25:29 +05:30
expect { click_on 'Import project' }.to change { Project.count }.by(1)
2016-08-24 12:49:21 +05:30
2017-09-10 17:25:29 +05:30
project = Project.last
expect(project).not_to be_nil
expect(page).to have_content("Project 'test-project-path' is being imported")
2016-09-13 17:45:13 +05:30
end
end
2017-09-10 17:25:29 +05:30
end
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
scenario 'invalid project' do
namespace = create(:namespace, name: "asd", owner: user)
project = create(:project, namespace: namespace)
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
visit new_project_path
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
select2(namespace.id, from: '#project_namespace_id')
fill_in :project_path, with: project.name, visible: true
click_link 'GitLab export'
attach_file('file', file)
click_on 'Import project'
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
page.within('.flash-container') do
expect(page).to have_content('Project could not be imported')
2016-08-24 12:49:21 +05:30
end
end
2016-11-03 12:29:30 +05:30
context 'when limited to the default user namespace' do
scenario 'passes correct namespace ID in the URL' do
2016-09-13 17:45:13 +05:30
visit new_project_path
2016-08-24 12:49:21 +05:30
2016-09-13 17:45:13 +05:30
fill_in :project_path, with: 'test-project-path', visible: true
2016-08-24 12:49:21 +05:30
2016-11-03 12:29:30 +05:30
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")
2016-08-24 12:49:21 +05:30
end
end
2016-11-03 12:29:30 +05:30
def wiki_exists?(project)
2016-06-22 15:30:34 +05:30
wiki = ProjectWiki.new(project)
File.exist?(wiki.repository.path_to_repo) && !wiki.repository.empty?
end
2016-11-03 12:29:30 +05:30
def project_hook_exists?(project)
2017-09-10 17:25:29 +05:30
Gitlab::Git::Hook.new('post-receive', project).exists?
2016-11-03 12:29:30 +05:30
end
2016-06-22 15:30:34 +05:30
end