Merge pull request #1363 from AlexDenisov/api_create_project_fixes
API create project fixes
This commit is contained in:
commit
7c0a1068bf
|
@ -102,6 +102,12 @@ Parameters:
|
|||
+ `name` (required) - new project name
|
||||
+ `code` (optional) - new project code, 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
|
||||
found` on fail.
|
||||
|
|
|
@ -29,14 +29,24 @@ module Gitlab
|
|||
# name (required) - name for new project
|
||||
# code (optional) - code 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
|
||||
# POST /projects
|
||||
post do
|
||||
project = {}
|
||||
project[:name] = params[:name]
|
||||
project[:code] = params[:code] || project[:name]
|
||||
project[:path] = params[:path] || project[:name]
|
||||
@project = Project.create_by_user(project, current_user)
|
||||
params[:code] ||= params[:name]
|
||||
params[:path] ||= params[:name]
|
||||
project_attrs = {}
|
||||
params.each_pair do |k ,v|
|
||||
if Project.attribute_names.include? k
|
||||
project_attrs[k] = v
|
||||
end
|
||||
end
|
||||
@project = Project.create_by_user(project_attrs, current_user)
|
||||
if @project.saved?
|
||||
present @project, with: Entities::Project
|
||||
else
|
||||
|
|
|
@ -11,6 +11,9 @@ module Factory
|
|||
def self.new(type, *args)
|
||||
FactoryGirl.build(type, *args)
|
||||
end
|
||||
def self.attributes(type, *args)
|
||||
FactoryGirl.attributes_for(type, *args)
|
||||
end
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
|
|
|
@ -27,38 +27,40 @@ describe Gitlab::API do
|
|||
|
||||
describe "POST /projects" do
|
||||
it "should create new project without code and path" do
|
||||
lambda {
|
||||
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)
|
||||
expect { post api("/projects", user), name: 'foo' }.to change {Project.count}.by(1)
|
||||
end
|
||||
it "should create new project" do
|
||||
lambda {
|
||||
name = "foo"
|
||||
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)
|
||||
|
||||
it "should not create new project without name" do
|
||||
expect { post api("/projects", user) }.to_not change {Project.count}
|
||||
end
|
||||
it "should not create project without name" do
|
||||
lambda {
|
||||
post api("/projects", user)
|
||||
response.status.should == 404
|
||||
}.should_not change{Project.count}
|
||||
|
||||
it "should respond with 201 on success" do
|
||||
post api("/projects", user), name: 'foo'
|
||||
response.status.should == 201
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue