2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Projects::CreateFromTemplateService do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:user) { create(:user) }
|
2018-11-18 11:00:15 +05:30
|
|
|
let(:template_name) { 'rails' }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project_params) do
|
|
|
|
{
|
2018-03-27 19:54:05 +05:30
|
|
|
path: user.to_param,
|
2018-11-18 11:00:15 +05:30
|
|
|
template_name: template_name,
|
2018-03-27 19:54:05 +05:30
|
|
|
description: 'project description',
|
2018-05-09 12:01:36 +05:30
|
|
|
visibility_level: Gitlab::VisibilityLevel::PUBLIC
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(user, project_params) }
|
|
|
|
|
|
|
|
it 'calls the importer service' do
|
2018-11-18 11:00:15 +05:30
|
|
|
import_service_double = double
|
|
|
|
|
|
|
|
allow(Projects::GitlabProjectsImportService).to receive(:new).and_return(import_service_double)
|
|
|
|
expect(import_service_double).to receive(:execute)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
subject.execute
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'returns the project that is created' do
|
2017-09-10 17:25:29 +05:30
|
|
|
project = subject.execute
|
|
|
|
|
|
|
|
expect(project).to be_saved
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(project.import_scheduled?).to be(true)
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
context 'when template is not present' do
|
|
|
|
let(:template_name) { 'non_existent' }
|
|
|
|
let(:project) { subject.execute }
|
|
|
|
|
|
|
|
before do
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(project).not_to be_saved
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not set import set import type' do
|
|
|
|
expect(project.import_type).to be nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not set import set import source' do
|
|
|
|
expect(project.import_source).to be nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not scheduled' do
|
2022-08-13 15:12:31 +05:30
|
|
|
expect(project.import_scheduled?).to be(false)
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'repository is empty' do
|
|
|
|
expect(project.repository.empty?).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
context 'the result project' do
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
perform_enqueued_jobs do
|
2018-05-09 12:01:36 +05:30
|
|
|
@project = subject.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
@project.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'overrides template description' do
|
|
|
|
expect(@project.description).to match('project description')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'overrides template visibility_level' do
|
|
|
|
expect(@project.visibility_level).to eq(Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|