2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-26 08:21:53 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::ProjectTemplate do
|
2017-07-26 08:21:53 -04:00
|
|
|
describe '.all' do
|
2020-06-11 14:08:28 -04:00
|
|
|
it 'returns all templates' do
|
|
|
|
expected = %w[
|
|
|
|
rails spring express iosswift dotnetcore android
|
|
|
|
gomicro gatsby hugo jekyll plainhtml gitbook
|
2020-10-01 08:10:14 -04:00
|
|
|
hexo sse_middleman gitpod_spring_petclinic nfhugo
|
|
|
|
nfjekyll nfplainhtml nfgitbook nfhexo salesforcedx
|
2021-10-22 14:13:20 -04:00
|
|
|
serverless_framework tencent_serverless_framework
|
|
|
|
jsonnet cluster_management kotlin_native_linux
|
2017-07-26 08:21:53 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
expect(described_class.all).to be_an(Array)
|
2020-06-11 14:08:28 -04:00
|
|
|
expect(described_class.all.map(&:name)).to match_array(expected)
|
2017-07-26 08:21:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-15 16:20:08 -04:00
|
|
|
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-07-26 08:21:53 -04:00
|
|
|
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-07-30 09:52:28 -04:00
|
|
|
describe '.archive_directory' do
|
|
|
|
subject { described_class.archive_directory }
|
|
|
|
|
|
|
|
it { is_expected.to be_a Pathname }
|
|
|
|
end
|
|
|
|
|
2017-07-26 08:21:53 -04:00
|
|
|
describe 'instance methods' do
|
2017-10-11 05:07:19 -04:00
|
|
|
subject { described_class.new('phoenix', 'Phoenix Framework', 'Phoenix description', 'link-to-template') }
|
2017-07-26 08:21:53 -04:00
|
|
|
|
2017-08-07 08:21:28 -04:00
|
|
|
it { is_expected.to respond_to(:logo, :file, :archive_path) }
|
2017-07-26 08:21:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validate all templates' do
|
2020-02-20 13:08:51 -05:00
|
|
|
let_it_be(:admin) { create(:admin) }
|
2017-08-01 08:34:11 -04:00
|
|
|
|
2017-07-26 08:21:53 -04:00
|
|
|
described_class.all.each do |template|
|
|
|
|
it "#{template.name} has a valid archive" do
|
2017-08-01 06:38:10 -04:00
|
|
|
archive = template.archive_path
|
2017-07-26 08:21:53 -04:00
|
|
|
|
|
|
|
expect(File.exist?(archive)).to be(true)
|
2017-08-01 08:34:11 -04:00
|
|
|
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
|
2017-07-26 08:21:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|