2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-26 08:21:53 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Projects::CreateFromTemplateService do
|
2017-07-26 08:21:53 -04:00
|
|
|
let(:user) { create(:user) }
|
2018-07-20 19:25:10 -04:00
|
|
|
let(:template_name) { 'rails' }
|
2017-07-26 08:21:53 -04:00
|
|
|
let(:project_params) do
|
|
|
|
{
|
2018-02-14 06:50:28 -05:00
|
|
|
path: user.to_param,
|
2018-07-20 19:25:10 -04:00
|
|
|
template_name: template_name,
|
2018-02-14 06:50:28 -05:00
|
|
|
description: 'project description',
|
2018-04-19 11:24:32 -04:00
|
|
|
visibility_level: Gitlab::VisibilityLevel::PUBLIC
|
2017-07-26 08:21:53 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(user, project_params) }
|
|
|
|
|
|
|
|
it 'calls the importer service' do
|
2018-07-20 19:25:10 -04:00
|
|
|
import_service_double = double
|
|
|
|
|
|
|
|
allow(Projects::GitlabProjectsImportService).to receive(:new).and_return(import_service_double)
|
|
|
|
expect(import_service_double).to receive(:execute)
|
2017-07-26 08:21:53 -04:00
|
|
|
|
|
|
|
subject.execute
|
|
|
|
end
|
|
|
|
|
2019-09-16 20:06:11 -04:00
|
|
|
it 'returns the project that is created' do
|
2017-07-26 08:21:53 -04:00
|
|
|
project = subject.execute
|
|
|
|
|
|
|
|
expect(project).to be_saved
|
2018-05-02 09:35:04 -04:00
|
|
|
expect(project.import_scheduled?).to be(true)
|
2018-04-19 11:24:32 -04:00
|
|
|
end
|
|
|
|
|
2018-07-20 19:25:10 -04:00
|
|
|
context 'when template is not present' do
|
|
|
|
let(:template_name) { 'non_existent' }
|
|
|
|
let(:project) { subject.execute }
|
|
|
|
|
|
|
|
before do
|
2019-09-16 20:06:11 -04:00
|
|
|
expect(project).not_to be_saved
|
2018-07-20 19:25:10 -04:00
|
|
|
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
|
2018-11-27 04:41:27 -05:00
|
|
|
expect(project.import_scheduled?).to be_nil
|
2018-07-20 19:25:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'repository is empty' do
|
|
|
|
expect(project.repository.empty?).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-19 11:24:32 -04:00
|
|
|
context 'the result project' do
|
|
|
|
before do
|
2018-07-23 00:34:54 -04:00
|
|
|
perform_enqueued_jobs do
|
2018-04-19 11:24:32 -04:00
|
|
|
@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-07-26 08:21:53 -04:00
|
|
|
end
|
|
|
|
end
|