Commit e078a173d6fad0ec79ed252f5e268f060c37508d
1 parent
0c5e5569
Exists in
master
and in
4 other branches
Create project via API: fixes added
Showing
3 changed files
with
61 additions
and
8 deletions
Show diff stats
doc/api/projects.md
| @@ -102,6 +102,12 @@ Parameters: | @@ -102,6 +102,12 @@ Parameters: | ||
| 102 | + `name` (required) - new project name | 102 | + `name` (required) - new project name |
| 103 | + `code` (optional) - new project code, uses project name if not set | 103 | + `code` (optional) - new project code, uses project name if not set |
| 104 | + `path` (optional) - new project path, uses project name if not set | 104 | + `path` (optional) - new project path, uses project name if not set |
| 105 | ++ `description (optional) - short project description | ||
| 106 | ++ `default_branch` (optional) - 'master' by default | ||
| 107 | ++ `issues_enabled` (optional) - enabled by default | ||
| 108 | ++ `wall_enabled` (optional) - enabled by default | ||
| 109 | ++ `merge_requests_enabled` (optional) - enabled by default | ||
| 110 | ++ `wiki_enabled` (optional) - enabled by default | ||
| 105 | 111 | ||
| 106 | Will return created project with status `201 Created` on success, or `404 Not | 112 | Will return created project with status `201 Created` on success, or `404 Not |
| 107 | found` on fail. | 113 | found` on fail. |
lib/api/projects.rb
| @@ -29,14 +29,26 @@ module Gitlab | @@ -29,14 +29,26 @@ module Gitlab | ||
| 29 | # name (required) - name for new project | 29 | # name (required) - name for new project |
| 30 | # code (optional) - code for new project, uses project name if not set | 30 | # code (optional) - code for new project, uses project name if not set |
| 31 | # path (optional) - path for new project, uses project name if not set | 31 | # path (optional) - path for new project, uses project name if not set |
| 32 | + # description (optional) - short project description | ||
| 33 | + # default_branch (optional) - 'master' by default | ||
| 34 | + # issues_enabled (optional) - enabled by default | ||
| 35 | + # wall_enabled (optional) - enabled by default | ||
| 36 | + # merge_requests_enabled (optional) - enabled by default | ||
| 37 | + # wiki_enabled (optional) - enabled by default | ||
| 32 | # Example Request | 38 | # Example Request |
| 33 | # POST /projects | 39 | # POST /projects |
| 34 | post do | 40 | post do |
| 35 | - project = {} | ||
| 36 | - project[:name] = params[:name] | ||
| 37 | - project[:code] = params[:code] || project[:name] | ||
| 38 | - project[:path] = params[:path] || project[:name] | ||
| 39 | - @project = Project.create_by_user(project, current_user) | 41 | + @project = Project.create_by_user({ |
| 42 | + name: params[:name], | ||
| 43 | + code: (params[:code] || params[:name]), | ||
| 44 | + path: (params[:path] || params[:name]), | ||
| 45 | + description: (params[:description] || Project.columns_hash["description"].default), | ||
| 46 | + default_branch: (params[:default_branch] || Project.columns_hash["default_branch"].default), | ||
| 47 | + issues_enabled: (params[:issues_enabled] || Project.columns_hash["issues_enabled"].default), | ||
| 48 | + wall_enabled: (params[:wall_enabled] || Project.columns_hash["wall_enabled"].default), | ||
| 49 | + merge_requests_enabled: (params[:merge_requests_enabled] || Project.columns_hash["merge_requests_enabled"].default), | ||
| 50 | + wiki_enabled: (params[:wiki_enabled] || Project.columns_hash["wiki_enabled"].default) | ||
| 51 | + }, current_user) | ||
| 40 | if @project.saved? | 52 | if @project.saved? |
| 41 | present @project, with: Entities::Project | 53 | present @project, with: Entities::Project |
| 42 | else | 54 | else |
spec/requests/api/projects_spec.rb
| @@ -27,7 +27,7 @@ describe Gitlab::API do | @@ -27,7 +27,7 @@ describe Gitlab::API do | ||
| 27 | 27 | ||
| 28 | describe "POST /projects" do | 28 | describe "POST /projects" do |
| 29 | it "should create new project without code and path" do | 29 | it "should create new project without code and path" do |
| 30 | - lambda { | 30 | + expect { |
| 31 | name = "foo" | 31 | name = "foo" |
| 32 | post api("/projects", user), { | 32 | post api("/projects", user), { |
| 33 | name: name | 33 | name: name |
| @@ -39,7 +39,41 @@ describe Gitlab::API do | @@ -39,7 +39,41 @@ describe Gitlab::API do | ||
| 39 | }.should change{Project.count}.by(1) | 39 | }.should change{Project.count}.by(1) |
| 40 | end | 40 | end |
| 41 | it "should create new project" do | 41 | it "should create new project" do |
| 42 | - lambda { | 42 | + expect { |
| 43 | + name = "foo" | ||
| 44 | + path = "bar" | ||
| 45 | + code = "bazz" | ||
| 46 | + description = "fuu project" | ||
| 47 | + default_branch = "default_branch" | ||
| 48 | + issues_enabled = false | ||
| 49 | + wall_enabled = false | ||
| 50 | + merge_requests_enabled = false | ||
| 51 | + wiki_enabled = false | ||
| 52 | + post api("/projects", user), { | ||
| 53 | + code: code, | ||
| 54 | + path: path, | ||
| 55 | + name: name, | ||
| 56 | + description: description, | ||
| 57 | + default_branch: default_branch, | ||
| 58 | + issues_enabled: issues_enabled, | ||
| 59 | + wall_enabled: wall_enabled, | ||
| 60 | + merge_requests_enabled: merge_requests_enabled, | ||
| 61 | + wiki_enabled: wiki_enabled | ||
| 62 | + } | ||
| 63 | + response.status.should == 201 | ||
| 64 | + json_response["name"].should == name | ||
| 65 | + json_response["path"].should == path | ||
| 66 | + json_response["code"].should == code | ||
| 67 | + json_response["description"].should == description | ||
| 68 | + json_response["default_branch"].should == default_branch | ||
| 69 | + json_response["issues_enabled"].should == issues_enabled | ||
| 70 | + json_response["wall_enabled"].should == wall_enabled | ||
| 71 | + json_response["merge_requests_enabled"].should == merge_requests_enabled | ||
| 72 | + json_response["wiki_enabled"].should == wiki_enabled | ||
| 73 | + }.should change{Project.count}.by(1) | ||
| 74 | + end | ||
| 75 | + it "should create new projects within all parameters" do | ||
| 76 | + expect { | ||
| 43 | name = "foo" | 77 | name = "foo" |
| 44 | path = "bar" | 78 | path = "bar" |
| 45 | code = "bazz" | 79 | code = "bazz" |
| @@ -53,9 +87,10 @@ describe Gitlab::API do | @@ -53,9 +87,10 @@ describe Gitlab::API do | ||
| 53 | json_response["path"].should == path | 87 | json_response["path"].should == path |
| 54 | json_response["code"].should == code | 88 | json_response["code"].should == code |
| 55 | }.should change{Project.count}.by(1) | 89 | }.should change{Project.count}.by(1) |
| 90 | + | ||
| 56 | end | 91 | end |
| 57 | it "should not create project without name" do | 92 | it "should not create project without name" do |
| 58 | - lambda { | 93 | + expect { |
| 59 | post api("/projects", user) | 94 | post api("/projects", user) |
| 60 | response.status.should == 404 | 95 | response.status.should == 404 |
| 61 | }.should_not change{Project.count} | 96 | }.should_not change{Project.count} |