2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-29 11:11:07 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
describe 'Import/Export - project import integration test', :js do
|
2018-09-03 20:20:57 +00:00
|
|
|
include GitHelpers
|
2016-04-29 11:11:07 +00:00
|
|
|
|
2017-08-21 15:50:34 +00:00
|
|
|
let(:user) { create(:user) }
|
2016-04-29 13:15:27 +00:00
|
|
|
let(:file) { File.join(Rails.root, 'spec', 'features', 'projects', 'import_export', 'test_project_export.tar.gz') }
|
2017-02-22 00:51:36 +00:00
|
|
|
let(:export_path) { "#{Dir.tmpdir}/import_file_spec" }
|
2016-05-09 16:07:29 +00:00
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
before do
|
2018-08-29 13:41:56 +00:00
|
|
|
stub_uploads_object_storage(FileUploader)
|
2019-11-14 03:06:25 +00:00
|
|
|
allow_next_instance_of(Gitlab::ImportExport) do |instance|
|
|
|
|
allow(instance).to receive(:storage_path).and_return(export_path)
|
|
|
|
end
|
2017-08-21 15:50:34 +00:00
|
|
|
gitlab_sign_in(user)
|
2016-04-29 11:11:07 +00:00
|
|
|
end
|
|
|
|
|
2017-08-10 22:31:42 +00:00
|
|
|
after do
|
2016-05-02 09:58:35 +00:00
|
|
|
FileUtils.rm_rf(export_path, secure: true)
|
|
|
|
end
|
|
|
|
|
2016-10-19 13:35:38 +00:00
|
|
|
context 'when selecting the namespace' do
|
|
|
|
let(:user) { create(:admin) }
|
2017-08-15 10:27:37 +00:00
|
|
|
let!(:namespace) { user.namespace }
|
2018-10-02 07:46:41 +00:00
|
|
|
let(:randomHex) { SecureRandom.hex }
|
|
|
|
let(:project_name) { 'Test Project Name' + randomHex }
|
|
|
|
let(:project_path) { 'test-project-name' + randomHex }
|
2016-10-19 13:35:38 +00:00
|
|
|
|
2017-08-21 15:50:34 +00:00
|
|
|
context 'prefilled the path' do
|
2019-10-23 09:06:03 +00:00
|
|
|
it 'user imports an exported project successfully', :sidekiq_might_not_need_inline do
|
2017-08-21 15:50:34 +00:00
|
|
|
visit new_project_path
|
2016-05-02 09:58:35 +00:00
|
|
|
|
2018-09-08 06:03:00 +00:00
|
|
|
fill_in :project_name, with: project_name, visible: true
|
2017-10-11 09:07:19 +00:00
|
|
|
click_import_project_tab
|
2017-08-21 15:50:34 +00:00
|
|
|
click_link 'GitLab export'
|
2016-04-29 11:11:07 +00:00
|
|
|
|
2017-08-21 15:50:34 +00:00
|
|
|
expect(page).to have_content('Import an exported GitLab project')
|
2018-09-08 06:03:00 +00:00
|
|
|
expect(URI.parse(current_url).query).to eq("namespace_id=#{namespace.id}&name=#{ERB::Util.url_encode(project_name)}&path=#{project_path}")
|
2016-04-29 13:15:27 +00:00
|
|
|
|
2017-08-21 15:50:34 +00:00
|
|
|
attach_file('file', file)
|
2017-09-04 16:07:37 +00:00
|
|
|
click_on 'Import project'
|
2016-04-29 13:15:27 +00:00
|
|
|
|
2017-09-04 16:07:37 +00:00
|
|
|
expect(Project.count).to eq(1)
|
2016-04-29 13:15:27 +00:00
|
|
|
|
2017-08-21 15:50:34 +00:00
|
|
|
project = Project.last
|
|
|
|
expect(project).not_to be_nil
|
2018-03-14 14:17:35 +00:00
|
|
|
expect(project.description).to eq("Foo Bar")
|
2017-08-21 15:50:34 +00:00
|
|
|
expect(project.issues).not_to be_empty
|
|
|
|
expect(project.merge_requests).not_to be_empty
|
|
|
|
expect(wiki_exists?(project)).to be true
|
2018-05-02 13:35:04 +00:00
|
|
|
expect(project.import_state.status).to eq('finished')
|
2017-08-21 15:50:34 +00:00
|
|
|
end
|
2016-08-11 14:59:37 +00:00
|
|
|
end
|
2016-05-05 14:24:09 +00:00
|
|
|
|
2017-08-21 15:50:34 +00:00
|
|
|
context 'path is not prefilled' do
|
2019-10-23 09:06:03 +00:00
|
|
|
it 'user imports an exported project successfully', :sidekiq_might_not_need_inline do
|
2017-08-21 15:50:34 +00:00
|
|
|
visit new_project_path
|
2017-10-11 09:07:19 +00:00
|
|
|
click_import_project_tab
|
2017-08-21 15:50:34 +00:00
|
|
|
click_link 'GitLab export'
|
2016-07-07 14:12:28 +00:00
|
|
|
|
2018-09-08 06:03:00 +00:00
|
|
|
fill_in :name, with: 'Test Project Name', visible: true
|
2017-08-21 15:50:34 +00:00
|
|
|
fill_in :path, with: 'test-project-path', visible: true
|
|
|
|
attach_file('file', file)
|
2016-07-07 14:12:28 +00:00
|
|
|
|
2017-08-21 15:50:34 +00:00
|
|
|
expect { click_on 'Import project' }.to change { Project.count }.by(1)
|
2016-07-07 14:12:28 +00:00
|
|
|
|
2017-08-21 15:50:34 +00:00
|
|
|
project = Project.last
|
|
|
|
expect(project).not_to be_nil
|
|
|
|
expect(page).to have_content("Project 'test-project-path' is being imported")
|
2016-08-11 14:59:37 +00:00
|
|
|
end
|
|
|
|
end
|
2016-07-07 14:12:28 +00:00
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'invalid project' do
|
2017-08-15 10:27:37 +00:00
|
|
|
project = create(:project, namespace: user.namespace)
|
2017-08-21 15:50:34 +00:00
|
|
|
|
|
|
|
visit new_project_path
|
|
|
|
|
2018-09-08 06:03:00 +00:00
|
|
|
fill_in :project_name, with: project.name, visible: true
|
2017-10-11 09:07:19 +00:00
|
|
|
click_import_project_tab
|
2017-08-21 15:50:34 +00:00
|
|
|
click_link 'GitLab export'
|
|
|
|
attach_file('file', file)
|
|
|
|
click_on 'Import project'
|
|
|
|
|
|
|
|
page.within('.flash-container') do
|
|
|
|
expect(page).to have_content('Project could not be imported')
|
2016-08-11 14:59:37 +00:00
|
|
|
end
|
2017-08-21 15:50:34 +00:00
|
|
|
end
|
2016-07-20 14:09:43 +00:00
|
|
|
|
2016-10-19 13:35:38 +00:00
|
|
|
def wiki_exists?(project)
|
2016-05-05 14:24:09 +00:00
|
|
|
wiki = ProjectWiki.new(project)
|
2018-06-05 15:51:14 +00:00
|
|
|
wiki.repository.exists? && !wiki.repository.empty?
|
2016-04-29 11:11:07 +00:00
|
|
|
end
|
2016-10-19 13:35:38 +00:00
|
|
|
|
2017-10-11 09:07:19 +00:00
|
|
|
def click_import_project_tab
|
2017-10-23 10:55:15 +00:00
|
|
|
find('#import-project-tab').click
|
2017-10-11 09:07:19 +00:00
|
|
|
end
|
2016-04-29 11:11:07 +00:00
|
|
|
end
|