summaryrefslogtreecommitdiff
path: root/spec/requests/api/templates_spec.rb
blob: 5bd5b861792da3b92f187bbcf4688547d4e17d95 (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'spec_helper'

describe API::Templates, api: true  do
  include ApiHelpers

  context 'global templates' do
    describe 'the Template Entity' do
      before { get api('/gitignores/Ruby') }

      it { expect(json_response['name']).to eq('Ruby') }
      it { expect(json_response['content']).to include('*.gem') }
    end

    describe 'the TemplateList Entity' do
      before { get api('/gitignores') }

      it { expect(json_response.first['name']).not_to be_nil }
      it { expect(json_response.first['content']).to be_nil }
    end

    context 'requesting gitignores' do
      describe 'GET /gitignores' do
        it 'returns a list of available gitignore templates' do
          get api('/gitignores')

          expect(response.status).to eq(200)
          expect(json_response).to be_an Array
          expect(json_response.size).to be > 15
        end
      end
    end

    context 'requesting gitlab-ci-ymls' do
      describe 'GET /gitlab_ci_ymls' do
        it 'returns a list of available gitlab_ci_ymls' do
          get api('/gitlab_ci_ymls')

          expect(response.status).to eq(200)
          expect(json_response).to be_an Array
          expect(json_response.first['name']).not_to be_nil
        end
      end
    end

    describe 'GET /gitlab_ci_ymls/Ruby' do
      it 'adds a disclaimer on the top' do
        get api('/gitlab_ci_ymls/Ruby')

        expect(response).to have_http_status(200)
        expect(json_response['name']).not_to be_nil
        expect(json_response['content']).to start_with("# This file is a template,")
      end
    end
  end
end