Commit 08ee177d authored by Jarka Kadlecova's avatar Jarka Kadlecova

API project create: Make name or path required

parent 90040620
---
title: 'API project create: Make name or path required'
merge_request: 9416
author:
......@@ -435,8 +435,8 @@ Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `name` | string | yes | The name of the new project |
| `path` | string | no | Custom repository name for new project. By default generated based on name |
| `name` | string | yes if path is not provided | The name of the new project. Equals path if not provided. |
| `path` | string | yes if name is not provided | Repository name for new project. Generated based on name if not provided (generated lowercased with dashes). |
| `namespace_id` | integer | no | Namespace for the new project (defaults to the current user's namespace) |
| `description` | string | no | Short project description |
| `issues_enabled` | boolean | no | Enable issues for this project |
......
......@@ -94,8 +94,9 @@ def present_projects(projects, options = {})
success Entities::Project
end
params do
requires :name, type: String, desc: 'The name of the project'
optional :name, type: String, desc: 'The name of the project'
optional :path, type: String, desc: 'The path of the repository'
at_least_one_of :name, :path
use :optional_params
use :create_params
end
......
......@@ -172,8 +172,9 @@ def present_projects(projects, options = {})
success ::API::Entities::Project
end
params do
requires :name, type: String, desc: 'The name of the project'
optional :name, type: String, desc: 'The name of the project'
optional :path, type: String, desc: 'The path of the repository'
at_least_one_of :name, :path
use :optional_params
use :create_params
end
......
......@@ -269,10 +269,37 @@
end
end
it 'creates new project without path and return 201' do
expect { post api('/projects', user), name: 'foo' }.
it 'creates new project without path but with name and returns 201' do
expect { post api('/projects', user), name: 'Foo Project' }.
to change { Project.count }.by(1)
expect(response).to have_http_status(201)
project = Project.first
expect(project.name).to eq('Foo Project')
expect(project.path).to eq('foo-project')
end
it 'creates new project without name but with path and returns 201' do
expect { post api('/projects', user), path: 'foo_project' }.
to change { Project.count }.by(1)
expect(response).to have_http_status(201)
project = Project.first
expect(project.name).to eq('foo_project')
expect(project.path).to eq('foo_project')
end
it 'creates new project name and path and returns 201' do
expect { post api('/projects', user), path: 'foo-Project', name: 'Foo Project' }.
to change { Project.count }.by(1)
expect(response).to have_http_status(201)
project = Project.first
expect(project.name).to eq('Foo Project')
expect(project.path).to eq('foo-Project')
end
it 'creates last project before reaching project limit' do
......@@ -281,7 +308,7 @@
expect(response).to have_http_status(201)
end
it 'does not create new project without name and return 400' do
it 'does not create new project without name or path and returns 400' do
expect { post api('/projects', user) }.not_to change { Project.count }
expect(response).to have_http_status(400)
end
......
......@@ -309,10 +309,37 @@
end
end
it 'creates new project without path and return 201' do
expect { post v3_api('/projects', user), name: 'foo' }.
it 'creates new project without path but with name and returns 201' do
expect { post v3_api('/projects', user), name: 'Foo Project' }.
to change { Project.count }.by(1)
expect(response).to have_http_status(201)
project = Project.first
expect(project.name).to eq('Foo Project')
expect(project.path).to eq('foo-project')
end
it 'creates new project without name but with path and returns 201' do
expect { post v3_api('/projects', user), path: 'foo_project' }.
to change { Project.count }.by(1)
expect(response).to have_http_status(201)
project = Project.first
expect(project.name).to eq('foo_project')
expect(project.path).to eq('foo_project')
end
it 'creates new project name and path and returns 201' do
expect { post v3_api('/projects', user), path: 'foo-Project', name: 'Foo Project' }.
to change { Project.count }.by(1)
expect(response).to have_http_status(201)
project = Project.first
expect(project.name).to eq('Foo Project')
expect(project.path).to eq('foo-Project')
end
it 'creates last project before reaching project limit' do
......@@ -321,7 +348,7 @@
expect(response).to have_http_status(201)
end
it 'does not create new project without name and return 400' do
it 'does not create new project without name or path and return 400' do
expect { post v3_api('/projects', user) }.not_to change { Project.count }
expect(response).to have_http_status(400)
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment