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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
6f05ea4f
Commit
6f05ea4f
authored
Jan 18, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve CreateContext call. Fixed test
parent
232d61d5
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
35 deletions
+47
-35
app/contexts/projects/create_context.rb
app/contexts/projects/create_context.rb
+7
-3
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+1
-1
lib/api/projects.rb
lib/api/projects.rb
+1
-1
spec/contexts/projects_create_context_spec.rb
spec/contexts/projects_create_context_spec.rb
+38
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+0
-30
No files found.
app/contexts/projects/create_context.rb
View file @
6f05ea4f
module
Projects
module
Projects
class
CreateContext
<
BaseContext
class
CreateContext
<
BaseContext
def
initialize
(
user
,
params
)
@current_user
,
@params
=
user
,
params
.
dup
end
def
execute
def
execute
# get namespace id
# get namespace id
namespace_id
=
params
[
:project
]
.
delete
(
:namespace_id
)
namespace_id
=
params
.
delete
(
:namespace_id
)
@project
=
Project
.
new
(
params
[
:project
]
)
@project
=
Project
.
new
(
params
)
# Parametrize path for project
# Parametrize path for project
#
#
...
@@ -25,7 +29,7 @@ module Projects
...
@@ -25,7 +29,7 @@ module Projects
end
end
else
else
# Set current user namespace if namespace_id is nil
# Set current user namespace if namespace_id is nil
@project
.
namespace_id
=
current_user
.
id
@project
.
namespace_id
=
current_user
.
namespace_
id
end
end
Project
.
transaction
do
Project
.
transaction
do
...
...
app/controllers/projects_controller.rb
View file @
6f05ea4f
...
@@ -19,7 +19,7 @@ class ProjectsController < ProjectResourceController
...
@@ -19,7 +19,7 @@ class ProjectsController < ProjectResourceController
end
end
def
create
def
create
@project
=
Projects
::
CreateContext
.
new
(
nil
,
current_user
,
params
).
execute
@project
=
Projects
::
CreateContext
.
new
(
current_user
,
params
).
execute
respond_to
do
|
format
|
respond_to
do
|
format
|
flash
[
:notice
]
=
'Project was successfully created.'
if
@project
.
saved?
flash
[
:notice
]
=
'Project was successfully created.'
if
@project
.
saved?
...
...
lib/api/projects.rb
View file @
6f05ea4f
...
@@ -43,7 +43,7 @@ module Gitlab
...
@@ -43,7 +43,7 @@ module Gitlab
:wall_enabled
,
:wall_enabled
,
:merge_requests_enabled
,
:merge_requests_enabled
,
:wiki_enabled
]
:wiki_enabled
]
@project
=
Projects
::
CreateContext
.
new
(
nil
,
attrs
,
current_user
).
execute
@project
=
::
Projects
::
CreateContext
.
new
(
current_user
,
attrs
).
execute
if
@project
.
saved?
if
@project
.
saved?
present
@project
,
with:
Entities
::
Project
present
@project
,
with:
Entities
::
Project
else
else
...
...
spec/contexts/projects_create_context_spec.rb
0 → 100644
View file @
6f05ea4f
require
'spec_helper'
describe
Projects
::
CreateContext
do
describe
:create_by_user
do
before
do
@user
=
create
:user
@opts
=
{
name:
"GitLab"
}
end
context
'user namespace'
do
before
do
@project
=
create_project
(
@user
,
@opts
)
end
it
{
@project
.
should
be_valid
}
it
{
@project
.
owner
.
should
==
@user
}
it
{
@project
.
namespace
.
should
==
@user
.
namespace
}
end
context
'group namespace'
do
before
do
@group
=
create
:group
,
owner:
@user
@opts
.
merge!
(
namespace_id:
@group
.
id
)
@project
=
create_project
(
@user
,
@opts
)
end
it
{
@project
.
should
be_valid
}
it
{
@project
.
owner
.
should
==
@user
}
it
{
@project
.
namespace
.
should
==
@group
}
end
end
def
create_project
(
user
,
opts
)
Projects
::
CreateContext
.
new
(
user
,
opts
).
execute
end
end
spec/models/project_spec.rb
View file @
6f05ea4f
...
@@ -153,36 +153,6 @@ describe Project do
...
@@ -153,36 +153,6 @@ describe Project do
end
end
end
end
describe
:create_by_user
do
before
do
@user
=
create
:user
@opts
=
{
name:
"GitLab"
}
end
context
'user namespace'
do
before
do
@project
=
Project
.
create_by_user
(
@opts
,
@user
)
end
it
{
@project
.
should
be_valid
}
it
{
@project
.
owner
.
should
==
@user
}
it
{
@project
.
namespace
.
should
==
@user
.
namespace
}
end
context
'user namespace'
do
before
do
@group
=
create
:group
,
owner:
@user
@opts
.
merge!
(
namespace_id:
@group
.
id
)
@project
=
Project
.
create_by_user
(
@opts
,
@user
)
end
it
{
@project
.
should
be_valid
}
it
{
@project
.
owner
.
should
==
@user
}
it
{
@project
.
namespace
.
should
==
@group
}
end
end
describe
:find_with_namespace
do
describe
:find_with_namespace
do
context
'with namespace'
do
context
'with namespace'
do
...
...
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