summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-04-11 15:49:25 +0200
committerRémy Coutable <remy@rymai.me>2016-04-18 14:47:50 +0200
commit13804aba867d19009ca94d820aa7ec650a509f5a (patch)
tree64c0d9415d81bb3104ba84af3834115f3a8cc5e1 /spec/requests
parent073c3d15c71a0f877b62c7d3d7417a9721da1dba (diff)
downloadgitlab-ce-13804aba867d19009ca94d820aa7ec650a509f5a.tar.gz
Continue implementation of the license template selector and /licenses API endpoint
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/licenses_spec.rb140
1 files changed, 115 insertions, 25 deletions
diff --git a/spec/requests/api/licenses_spec.rb b/spec/requests/api/licenses_spec.rb
index f0f8b041f69..61a58231c54 100644
--- a/spec/requests/api/licenses_spec.rb
+++ b/spec/requests/api/licenses_spec.rb
@@ -1,45 +1,135 @@
require 'spec_helper'
-describe API::API, api: true do
+describe API::Licenses, api: true do
include ApiHelpers
- describe 'GET /licenses/:key' do
- before(:each) do
- get api("/licenses/#{license_type}?fullname=Anton")
+
+ describe 'Entity' do
+ before { get api('/licenses/mit') }
+
+ it { expect(json_response['key']).to eq('mit') }
+ it { expect(json_response['name']).to eq('MIT License') }
+ it { expect(json_response['nickname']).to be_nil }
+ it { expect(json_response['featured']).to be true }
+ it { expect(json_response['html_url']).to eq('http://choosealicense.com/licenses/mit/') }
+ it { expect(json_response['source_url']).to eq('http://opensource.org/licenses/MIT') }
+ it { expect(json_response['description']).to include('A permissive license that is short and to the point.') }
+ it { expect(json_response['conditions']).to eq(%w[include-copyright]) }
+ it { expect(json_response['permissions']).to eq(%w[commercial-use modifications distribution private-use]) }
+ it { expect(json_response['limitations']).to eq(%w[no-liability]) }
+ it { expect(json_response['content']).to include('The MIT License (MIT)') }
+ end
+
+ describe 'GET /licenses' do
+ it 'returns a list of available license templates' do
+ get api('/licenses')
+
+ expect(response.status).to eq(200)
+ expect(json_response).to be_an Array
+ expect(json_response.size).to eq(15)
+ expect(json_response.first['key']).to eq('agpl-3.0')
end
- context 'for mit license name' do
- let(:license_type){ 'mit' }
+ describe 'the popular parameter' do
+ context 'with popular=1' do
+ it 'returns a list of available popular license templates' do
+ get api('/licenses?popular=1')
- it 'returns MIT license text and replases template values' do
- expect(response.body).to include('Copyright (c) 2016 Anton')
- expect(response.body).to include('Copyright (c) 2016')
+ expect(response.status).to eq(200)
+ expect(json_response).to be_an Array
+ expect(json_response.size).to eq(3)
+ expect(json_response.first['key']).to eq('apache-2.0')
+ end
end
end
+ end
- context 'for gnu license name' do
- let(:license_type){ 'gpl-3.0' }
+ describe 'GET /licenses/:key' do
+ context 'with :project and :fullname given' do
+ before do
+ get api("/licenses/#{license_type}?project=My+Awesome+Project&fullname=Anton+#{license_type.upcase}")
+ end
+
+ context 'for the mit license' do
+ let(:license_type) { 'mit' }
- it 'returns GNU license text and replases template values' do
- expect(response.body).to include('GNU GENERAL PUBLIC LICENSE')
- expect(response.body).to include('Copyright (C) 2016')
+ it 'returns the license text' do
+ expect(json_response['content']).to include('The MIT License (MIT)')
+ end
+
+ it 'replaces placeholder values' do
+ expect(json_response['content']).to include('Copyright (c) 2016 Anton')
+ end
end
- end
- context 'for apache license name' do
- let(:license_type){ 'apache-2.0' }
+ context 'for the agpl-3.0 license' do
+ let(:license_type) { 'agpl-3.0' }
- it 'returns Apache license text and replases template values' do
- expect(response.body).to include('Apache License')
- expect(response.body).to include('Copyright 2016')
+ 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) 2016 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) 2016 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) 2016 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 2016 Anton')
+ end
+ end
+
+ context 'for an uknown license' do
+ let(:license_type) { 'muth-over9000' }
+
+ it 'returns a 404' do
+ expect(response.status).to eq(404)
+ end
end
end
- context 'for mythic license name' do
- let(:license_type){ 'muth-over9000' }
+ 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('/licenses/mit', user)
- it 'returns string with error' do
- expect(response).to have_http_status(404)
- expect(response.body).to eq 'License not found'
+ expect(json_response['content']).to include("Copyright (c) 2016 #{user.name}")
+ end
end
end
end