Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
7c0a1068
Commit
7c0a1068
authored
Sep 06, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1363 from AlexDenisov/api_create_project_fixes
API create project fixes
parents
687dc0dc
9b9dd3f9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
37 deletions
+58
-37
doc/api/projects.md
doc/api/projects.md
+6
-0
lib/api/projects.rb
lib/api/projects.rb
+15
-5
spec/factories.rb
spec/factories.rb
+3
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+34
-32
No files found.
doc/api/projects.md
View file @
7c0a1068
...
@@ -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.
...
...
lib/api/projects.rb
View file @
7c0a1068
...
@@ -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
...
...
spec/factories.rb
View file @
7c0a1068
...
@@ -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
...
...
spec/requests/api/projects_spec.rb
View file @
7c0a1068
...
@@ -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
)
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
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 repsond with 404 on failure"
do
post
api
(
"/projects"
,
user
)
post
api
(
"/projects"
,
user
)
response
.
status
.
should
==
404
response
.
status
.
should
==
404
}.
should_not
change
{
Project
.
count
}
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment