Merge pull request #1363 from AlexDenisov/api_create_project_fixes
API create project fixes
This commit is contained in:
commit
7c0a1068bf
4 changed files with 56 additions and 35 deletions
|
@ -102,6 +102,12 @@ Parameters:
|
||||||
+ `name` (required) - new project name
|
+ `name` (required) - new project name
|
||||||
+ `code` (optional) - new project code, uses project name if not set
|
+ `code` (optional) - new project code, uses project name if not set
|
||||||
+ `path` (optional) - new project path, uses project name if not set
|
+ `path` (optional) - new project path, uses project name if not set
|
||||||
|
+ `description (optional) - short project description
|
||||||
|
+ `default_branch` (optional) - 'master' by default
|
||||||
|
+ `issues_enabled` (optional) - enabled by default
|
||||||
|
+ `wall_enabled` (optional) - enabled by default
|
||||||
|
+ `merge_requests_enabled` (optional) - enabled by default
|
||||||
|
+ `wiki_enabled` (optional) - enabled by default
|
||||||
|
|
||||||
Will return created project with status `201 Created` on success, or `404 Not
|
Will return created project with status `201 Created` on success, or `404 Not
|
||||||
found` on fail.
|
found` on fail.
|
||||||
|
|
|
@ -29,14 +29,24 @@ module Gitlab
|
||||||
# name (required) - name for new project
|
# name (required) - name for new project
|
||||||
# code (optional) - code for new project, uses project name if not set
|
# code (optional) - code for new project, uses project name if not set
|
||||||
# path (optional) - path for new project, uses project name if not set
|
# path (optional) - path for new project, uses project name if not set
|
||||||
|
# description (optional) - short project description
|
||||||
|
# default_branch (optional) - 'master' by default
|
||||||
|
# issues_enabled (optional) - enabled by default
|
||||||
|
# wall_enabled (optional) - enabled by default
|
||||||
|
# merge_requests_enabled (optional) - enabled by default
|
||||||
|
# wiki_enabled (optional) - enabled by default
|
||||||
# Example Request
|
# Example Request
|
||||||
# POST /projects
|
# POST /projects
|
||||||
post do
|
post do
|
||||||
project = {}
|
params[:code] ||= params[:name]
|
||||||
project[:name] = params[:name]
|
params[:path] ||= params[:name]
|
||||||
project[:code] = params[:code] || project[:name]
|
project_attrs = {}
|
||||||
project[:path] = params[:path] || project[:name]
|
params.each_pair do |k ,v|
|
||||||
@project = Project.create_by_user(project, current_user)
|
if Project.attribute_names.include? k
|
||||||
|
project_attrs[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@project = Project.create_by_user(project_attrs, current_user)
|
||||||
if @project.saved?
|
if @project.saved?
|
||||||
present @project, with: Entities::Project
|
present @project, with: Entities::Project
|
||||||
else
|
else
|
||||||
|
|
|
@ -11,6 +11,9 @@ module Factory
|
||||||
def self.new(type, *args)
|
def self.new(type, *args)
|
||||||
FactoryGirl.build(type, *args)
|
FactoryGirl.build(type, *args)
|
||||||
end
|
end
|
||||||
|
def self.attributes(type, *args)
|
||||||
|
FactoryGirl.attributes_for(type, *args)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
|
|
|
@ -27,38 +27,40 @@ describe Gitlab::API do
|
||||||
|
|
||||||
describe "POST /projects" do
|
describe "POST /projects" do
|
||||||
it "should create new project without code and path" do
|
it "should create new project without code and path" do
|
||||||
lambda {
|
expect { post api("/projects", user), name: 'foo' }.to change {Project.count}.by(1)
|
||||||
name = "foo"
|
|
||||||
post api("/projects", user), {
|
|
||||||
name: name
|
|
||||||
}
|
|
||||||
response.status.should == 201
|
|
||||||
json_response["name"].should == name
|
|
||||||
json_response["code"].should == name
|
|
||||||
json_response["path"].should == name
|
|
||||||
}.should change{Project.count}.by(1)
|
|
||||||
end
|
end
|
||||||
it "should create new project" do
|
|
||||||
lambda {
|
it "should not create new project without name" do
|
||||||
name = "foo"
|
expect { post api("/projects", user) }.to_not change {Project.count}
|
||||||
path = "bar"
|
|
||||||
code = "bazz"
|
|
||||||
post api("/projects", user), {
|
|
||||||
code: code,
|
|
||||||
path: path,
|
|
||||||
name: name
|
|
||||||
}
|
|
||||||
response.status.should == 201
|
|
||||||
json_response["name"].should == name
|
|
||||||
json_response["path"].should == path
|
|
||||||
json_response["code"].should == code
|
|
||||||
}.should change{Project.count}.by(1)
|
|
||||||
end
|
end
|
||||||
it "should not create project without name" do
|
|
||||||
lambda {
|
it "should respond with 201 on success" do
|
||||||
post api("/projects", user)
|
post api("/projects", user), name: 'foo'
|
||||||
response.status.should == 404
|
response.status.should == 201
|
||||||
}.should_not change{Project.count}
|
end
|
||||||
|
|
||||||
|
it "should repsond with 404 on failure" do
|
||||||
|
post api("/projects", user)
|
||||||
|
response.status.should == 404
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should assign attributes to project" do
|
||||||
|
project = Factory.attributes(:project, {
|
||||||
|
path: 'path',
|
||||||
|
code: 'code',
|
||||||
|
description: Faker::Lorem.sentence,
|
||||||
|
default_branch: 'stable',
|
||||||
|
issues_enabled: false,
|
||||||
|
wall_enabled: false,
|
||||||
|
merge_requests_enabled: false,
|
||||||
|
wiki_enabled: false
|
||||||
|
})
|
||||||
|
|
||||||
|
post api("/projects", user), project
|
||||||
|
|
||||||
|
project.each_pair do |k,v|
|
||||||
|
json_response[k.to_s].should == v
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue