2016-06-02 12:20:08 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-21 16:32:02 -04:00
|
|
|
describe API::Templates do
|
2017-01-27 13:53:27 -05:00
|
|
|
context 'the Template Entity' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
get api('/templates/gitignores/Ruby')
|
|
|
|
end
|
2016-06-02 12:20:08 -04:00
|
|
|
|
2016-08-08 07:42:24 -04:00
|
|
|
it { expect(json_response['name']).to eq('Ruby') }
|
|
|
|
it { expect(json_response['content']).to include('*.gem') }
|
|
|
|
end
|
2017-01-27 13:53:27 -05:00
|
|
|
|
|
|
|
context 'the TemplateList Entity' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
get api('/templates/gitignores')
|
|
|
|
end
|
2016-08-08 07:42:24 -04:00
|
|
|
|
|
|
|
it { expect(json_response.first['name']).not_to be_nil }
|
|
|
|
it { expect(json_response.first['content']).to be_nil }
|
|
|
|
end
|
|
|
|
|
2017-01-27 13:53:27 -05:00
|
|
|
context 'requesting gitignores' do
|
2016-08-08 07:42:24 -04:00
|
|
|
it 'returns a list of available gitignore templates' do
|
2017-01-27 13:53:27 -05:00
|
|
|
get api('/templates/gitignores')
|
2016-08-08 07:42:24 -04:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2016-08-08 07:42:24 -04:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.size).to be > 15
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
2016-08-08 07:42:24 -04:00
|
|
|
end
|
2016-06-02 12:20:08 -04:00
|
|
|
|
2017-01-27 13:53:27 -05:00
|
|
|
context 'requesting gitlab-ci-ymls' do
|
2016-08-08 07:42:24 -04:00
|
|
|
it 'returns a list of available gitlab_ci_ymls' do
|
2017-01-27 13:53:27 -05:00
|
|
|
get api('/templates/gitlab_ci_ymls')
|
2016-06-02 12:20:08 -04:00
|
|
|
|
2016-08-08 07:42:24 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2016-08-08 07:42:24 -04:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.first['name']).not_to be_nil
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
2016-08-08 07:42:24 -04:00
|
|
|
end
|
|
|
|
|
2017-01-27 13:53:27 -05:00
|
|
|
context 'requesting gitlab-ci-yml for Ruby' do
|
2016-08-08 07:42:24 -04:00
|
|
|
it 'adds a disclaimer on the top' do
|
2017-01-27 13:53:27 -05:00
|
|
|
get api('/templates/gitlab_ci_ymls/Ruby')
|
2016-08-08 07:42:24 -04:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response['content']).to start_with("# This file is a template,")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-27 13:53:27 -05:00
|
|
|
context 'the License Template Entity' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
get api('/templates/licenses/mit')
|
|
|
|
end
|
2016-08-08 07:42:24 -04:00
|
|
|
|
|
|
|
it 'returns a license template' do
|
|
|
|
expect(json_response['key']).to eq('mit')
|
|
|
|
expect(json_response['name']).to eq('MIT License')
|
|
|
|
expect(json_response['nickname']).to be_nil
|
|
|
|
expect(json_response['popular']).to be true
|
|
|
|
expect(json_response['html_url']).to eq('http://choosealicense.com/licenses/mit/')
|
|
|
|
expect(json_response['source_url']).to eq('https://opensource.org/licenses/MIT')
|
2017-02-22 13:38:10 -05:00
|
|
|
expect(json_response['description']).to include('A short and simple permissive license with conditions')
|
2016-08-08 07:42:24 -04:00
|
|
|
expect(json_response['conditions']).to eq(%w[include-copyright])
|
|
|
|
expect(json_response['permissions']).to eq(%w[commercial-use modifications distribution private-use])
|
|
|
|
expect(json_response['limitations']).to eq(%w[no-liability])
|
2017-02-22 13:38:10 -05:00
|
|
|
expect(json_response['content']).to include('MIT License')
|
2016-08-08 07:42:24 -04:00
|
|
|
end
|
|
|
|
end
|
2016-06-02 12:20:08 -04:00
|
|
|
|
2017-01-27 13:53:27 -05:00
|
|
|
context 'GET templates/licenses' do
|
2016-08-08 07:42:24 -04:00
|
|
|
it 'returns a list of available license templates' do
|
2017-01-27 13:53:27 -05:00
|
|
|
get api('/templates/licenses')
|
2016-06-02 12:20:08 -04:00
|
|
|
|
2016-08-08 07:42:24 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2016-08-08 07:42:24 -04:00
|
|
|
expect(json_response).to be_an Array
|
2017-02-22 13:38:10 -05:00
|
|
|
expect(json_response.size).to eq(12)
|
2016-08-08 07:42:24 -04:00
|
|
|
expect(json_response.map { |l| l['key'] }).to include('agpl-3.0')
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'the popular parameter' do
|
|
|
|
context 'with popular=1' do
|
|
|
|
it 'returns a list of available popular license templates' do
|
2017-01-27 13:53:27 -05:00
|
|
|
get api('/templates/licenses?popular=1')
|
2016-08-08 07:42:24 -04:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2016-06-24 15:43:46 -04:00
|
|
|
expect(json_response).to be_an Array
|
2016-08-08 07:42:24 -04:00
|
|
|
expect(json_response.size).to eq(3)
|
|
|
|
expect(json_response.map { |l| l['key'] }).to include('apache-2.0')
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
2016-06-02 12:20:08 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-08 07:42:24 -04:00
|
|
|
end
|
2016-06-02 12:20:08 -04:00
|
|
|
|
2017-01-27 13:53:27 -05:00
|
|
|
context 'GET templates/licenses/:name' do
|
2016-08-08 07:42:24 -04:00
|
|
|
context 'with :project and :fullname given' do
|
|
|
|
before do
|
2017-01-27 13:53:27 -05:00
|
|
|
get api("/templates/licenses/#{license_type}?project=My+Awesome+Project&fullname=Anton+#{license_type.upcase}")
|
2016-08-08 07:42:24 -04:00
|
|
|
end
|
2016-06-02 12:20:08 -04:00
|
|
|
|
2016-08-08 07:42:24 -04:00
|
|
|
context 'for the mit license' do
|
|
|
|
let(:license_type) { 'mit' }
|
|
|
|
|
|
|
|
it 'returns the license text' do
|
2017-02-22 13:38:10 -05:00
|
|
|
expect(json_response['content']).to include('MIT License')
|
2016-08-08 07:42:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'replaces placeholder values' do
|
|
|
|
expect(json_response['content']).to include("Copyright (c) #{Time.now.year} Anton")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for the agpl-3.0 license' do
|
|
|
|
let(:license_type) { 'agpl-3.0' }
|
|
|
|
|
|
|
|
it 'returns the license text' do
|
|
|
|
expect(json_response['content']).to include('GNU AFFERO GENERAL PUBLIC LICENSE')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'replaces placeholder values' do
|
|
|
|
expect(json_response['content']).to include('My Awesome Project')
|
|
|
|
expect(json_response['content']).to include("Copyright (C) #{Time.now.year} Anton")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for the gpl-3.0 license' do
|
|
|
|
let(:license_type) { 'gpl-3.0' }
|
|
|
|
|
|
|
|
it 'returns the license text' do
|
|
|
|
expect(json_response['content']).to include('GNU GENERAL PUBLIC LICENSE')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'replaces placeholder values' do
|
|
|
|
expect(json_response['content']).to include('My Awesome Project')
|
|
|
|
expect(json_response['content']).to include("Copyright (C) #{Time.now.year} Anton")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for the gpl-2.0 license' do
|
|
|
|
let(:license_type) { 'gpl-2.0' }
|
|
|
|
|
|
|
|
it 'returns the license text' do
|
|
|
|
expect(json_response['content']).to include('GNU GENERAL PUBLIC LICENSE')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'replaces placeholder values' do
|
|
|
|
expect(json_response['content']).to include('My Awesome Project')
|
|
|
|
expect(json_response['content']).to include("Copyright (C) #{Time.now.year} Anton")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for the apache-2.0 license' do
|
|
|
|
let(:license_type) { 'apache-2.0' }
|
|
|
|
|
|
|
|
it 'returns the license text' do
|
|
|
|
expect(json_response['content']).to include('Apache License')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'replaces placeholder values' do
|
|
|
|
expect(json_response['content']).to include("Copyright #{Time.now.year} Anton")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for an uknown license' do
|
|
|
|
let(:license_type) { 'muth-over9000' }
|
|
|
|
|
|
|
|
it 'returns a 404' do
|
|
|
|
expect(response).to have_http_status(404)
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
2016-06-02 12:20:08 -04:00
|
|
|
end
|
|
|
|
end
|
2016-06-16 09:33:11 -04:00
|
|
|
|
2016-08-08 07:42:24 -04:00
|
|
|
context 'with no :fullname given' do
|
|
|
|
context 'with an authenticated user' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
it 'replaces the copyright owner placeholder with the name of the current user' do
|
|
|
|
get api('/templates/licenses/mit', user)
|
2016-06-16 09:33:11 -04:00
|
|
|
|
2016-08-08 07:42:24 -04:00
|
|
|
expect(json_response['content']).to include("Copyright (c) #{Time.now.year} #{user.name}")
|
|
|
|
end
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
2016-06-16 09:33:11 -04:00
|
|
|
end
|
|
|
|
end
|
2016-06-02 12:20:08 -04:00
|
|
|
end
|