Commit 7c0a1068 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #1363 from AlexDenisov/api_create_project_fixes

API create project fixes
parents 687dc0dc 9b9dd3f9
...@@ -102,6 +102,12 @@ Parameters: ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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" end
post api("/projects", user), {
name: name it "should not create new project without name" do
} expect { post api("/projects", user) }.to_not change {Project.count}
response.status.should == 201 end
json_response["name"].should == name
json_response["code"].should == name it "should respond with 201 on success" do
json_response["path"].should == name post api("/projects", user), name: 'foo'
}.should change{Project.count}.by(1) response.status.should == 201
end end
it "should create new project" do
lambda { it "should repsond with 404 on failure" do
name = "foo" post api("/projects", user)
path = "bar" response.status.should == 404
code = "bazz" end
post api("/projects", user), {
code: code, it "should assign attributes to project" do
path: path, project = Factory.attributes(:project, {
name: name path: 'path',
} code: 'code',
response.status.should == 201 description: Faker::Lorem.sentence,
json_response["name"].should == name default_branch: 'stable',
json_response["path"].should == path issues_enabled: false,
json_response["code"].should == code wall_enabled: false,
}.should change{Project.count}.by(1) merge_requests_enabled: false,
end wiki_enabled: false
it "should not create project without name" do })
lambda {
post api("/projects", user) post api("/projects", user), project
response.status.should == 404
}.should_not change{Project.count} project.each_pair do |k,v|
json_response[k.to_s].should == v
end
end end
end 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