diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-08-01 11:54:23 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-08-01 11:54:23 +0300 |
commit | bd659f70b18be07dac184ca249c7eee17c703e56 (patch) | |
tree | 0c2091386dc5528f27928d1c5868eea2f140226e /spec/services/projects | |
parent | e53e4d45296c32e699b98cefdcb4bcde5e1a44bf (diff) | |
parent | 60943a60d822ea490c65914ca3cec5a488742c93 (diff) |
Merge branch 'fj-6860-instance-level-project-templates' into 'master'
[CE Port]: Implement instance level project templates
See merge request gitlab-org/gitlab-ce!20761
Diffstat (limited to 'spec/services/projects')
-rw-r--r-- | spec/services/projects/create_from_template_service_spec.rb | 33 | ||||
-rw-r--r-- | spec/services/projects/gitlab_projects_import_service_spec.rb | 54 |
2 files changed, 33 insertions, 54 deletions
diff --git a/spec/services/projects/create_from_template_service_spec.rb b/spec/services/projects/create_from_template_service_spec.rb index a43da01f37e..141ccf7c4d8 100644 --- a/spec/services/projects/create_from_template_service_spec.rb +++ b/spec/services/projects/create_from_template_service_spec.rb @@ -2,10 +2,11 @@ require 'spec_helper' describe Projects::CreateFromTemplateService do let(:user) { create(:user) } + let(:template_name) { 'rails' } let(:project_params) do { path: user.to_param, - template_name: 'rails', + template_name: template_name, description: 'project description', visibility_level: Gitlab::VisibilityLevel::PUBLIC } @@ -14,7 +15,10 @@ describe Projects::CreateFromTemplateService do subject { described_class.new(user, project_params) } it 'calls the importer service' do - expect_any_instance_of(Projects::GitlabProjectsImportService).to receive(:execute) + import_service_double = double + + allow(Projects::GitlabProjectsImportService).to receive(:new).and_return(import_service_double) + expect(import_service_double).to receive(:execute) subject.execute end @@ -26,6 +30,31 @@ describe Projects::CreateFromTemplateService do expect(project.import_scheduled?).to be(true) end + context 'when template is not present' do + let(:template_name) { 'non_existent' } + let(:project) { subject.execute } + + before do + expect(project).to be_saved + 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 + expect(project.import_scheduled?).to be(false) + end + + it 'repository is empty' do + expect(project.repository.empty?).to be(true) + end + end + context 'the result project' do before do perform_enqueued_jobs do diff --git a/spec/services/projects/gitlab_projects_import_service_spec.rb b/spec/services/projects/gitlab_projects_import_service_spec.rb index 0a898e9b89b..a2061127698 100644 --- a/spec/services/projects/gitlab_projects_import_service_spec.rb +++ b/spec/services/projects/gitlab_projects_import_service_spec.rb @@ -6,60 +6,10 @@ describe Projects::GitlabProjectsImportService do let(:file) { fixture_file_upload('spec/fixtures/doc_sample.txt', 'text/plain') } let(:overwrite) { false } let(:import_params) { { namespace_id: namespace.id, path: path, file: file, overwrite: overwrite } } + subject { described_class.new(namespace.owner, import_params) } describe '#execute' do - context 'with an invalid path' do - let(:path) { '/invalid-path/' } - - it 'returns an invalid project' do - project = subject.execute - - expect(project).not_to be_persisted - expect(project).not_to be_valid - end - end - - context 'with a valid path' do - it 'creates a project' do - project = subject.execute - - expect(project).to be_persisted - expect(project).to be_valid - end - end - - context 'override params' do - it 'stores them as import data when passed' do - project = described_class - .new(namespace.owner, import_params, description: 'Hello') - .execute - - expect(project.import_data.data['override_params']['description']).to eq('Hello') - end - end - - context 'when there is a project with the same path' do - let(:existing_project) { create(:project, namespace: namespace) } - let(:path) { existing_project.path} - - it 'does not create the project' do - project = subject.execute - - expect(project).to be_invalid - expect(project).not_to be_persisted - end - - context 'when overwrite param is set' do - let(:overwrite) { true } - - it 'creates a project in a temporary full_path' do - project = subject.execute - - expect(project).to be_valid - expect(project).to be_persisted - end - end - end + it_behaves_like 'gitlab projects import validations' end end |