2019-12-04 20:38:33 +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 Gitlab::ProjectTemplate do
|
2022-07-23 23:45:48 +05:30
|
|
|
include ProjectTemplateTestHelper
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '.all' do
|
2020-06-23 00:09:42 +05:30
|
|
|
it 'returns all templates' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(described_class.all).to be_an(Array)
|
2022-07-23 23:45:48 +05:30
|
|
|
expect(described_class.all.map(&:name)).to match_array(all_templates)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
describe '#project_path' do
|
|
|
|
subject { described_class.new('name', 'title', 'description', 'https://gitlab.com/some/project/path').project_path }
|
|
|
|
|
|
|
|
it { is_expected.to eq 'some/project/path' }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#uri_encoded_project_path' do
|
|
|
|
subject { described_class.new('name', 'title', 'description', 'https://gitlab.com/some/project/path').uri_encoded_project_path }
|
|
|
|
|
|
|
|
it { is_expected.to eq 'some%2Fproject%2Fpath' }
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '.find' do
|
|
|
|
subject { described_class.find(query) }
|
|
|
|
|
|
|
|
context 'when there is a match' do
|
|
|
|
let(:query) { :rails }
|
|
|
|
|
|
|
|
it { is_expected.to be_a(described_class) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is no match' do
|
|
|
|
let(:query) { 'no-match' }
|
|
|
|
|
|
|
|
it { is_expected.to be(nil) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
describe '.archive_directory' do
|
|
|
|
subject { described_class.archive_directory }
|
|
|
|
|
|
|
|
it { is_expected.to be_a Pathname }
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe 'instance methods' do
|
2018-03-17 18:26:18 +05:30
|
|
|
subject { described_class.new('phoenix', 'Phoenix Framework', 'Phoenix description', 'link-to-template') }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
it { is_expected.to respond_to(:logo, :file, :archive_path) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validate all templates' do
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:admin) { create(:admin) }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
described_class.all.each do |template|
|
|
|
|
it "#{template.name} has a valid archive" do
|
|
|
|
archive = template.archive_path
|
|
|
|
|
|
|
|
expect(File.exist?(archive)).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with valid parameters' do
|
|
|
|
it 'can be imported' do
|
|
|
|
params = {
|
|
|
|
template_name: template.name,
|
|
|
|
namespace_id: admin.namespace.id,
|
|
|
|
path: template.name
|
|
|
|
}
|
|
|
|
|
|
|
|
project = Projects::CreateFromTemplateService.new(admin, params).execute
|
|
|
|
|
|
|
|
expect(project).to be_valid
|
|
|
|
expect(project).to be_persisted
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|