project_template_spec.rb 1.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
require 'spec_helper'

describe Gitlab::ProjectTemplate do
  describe '.all' do
    it 'returns a all templates' do
      expected = [
        described_class.new('rails', 'Ruby on Rails')
      ]

      expect(described_class.all).to be_an(Array)
      expect(described_class.all).to eq(expected)
    end
  end

  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

  describe 'instance methods' do
    subject { described_class.new('phoenix', 'Phoenix Framework') }

34
    it { is_expected.to respond_to(:logo_path, :file, :archive_path) }
35 36 37
  end

  describe 'validate all templates' do
38 39
    set(:admin) { create(:admin) }

40 41
    described_class.all.each do |template|
      it "#{template.name} has a valid archive" do
42
        archive = template.archive_path
43 44

        expect(File.exist?(archive)).to be(true)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
      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
60 61 62 63
      end
    end
  end
end