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
Jérome Perrin
gitlab-ce
Commits
daf26fa0
Commit
daf26fa0
authored
Nov 20, 2016
by
Semyon Pupkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor create service spec
before: 1 minute 11.81 seconds after: 52.47 seconds
parent
7902395f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
106 deletions
+110
-106
changelogs/unreleased/refactor-create-service-spec.yml
changelogs/unreleased/refactor-create-service-spec.yml
+4
-0
spec/services/projects/create_service_spec.rb
spec/services/projects/create_service_spec.rb
+106
-106
No files found.
changelogs/unreleased/refactor-create-service-spec.yml
0 → 100644
View file @
daf26fa0
---
title
:
Refactor create service spec
merge_request
:
7609
author
:
Semyon Pupkov
spec/services/projects/create_service_spec.rb
View file @
daf26fa0
require
'spec_helper'
require
'spec_helper'
describe
Projects
::
CreateService
,
services:
true
do
describe
Projects
::
CreateService
,
'#execute'
,
services:
true
do
describe
:create_by_user
do
let
(
:user
)
{
create
:user
}
before
do
let
(
:opts
)
do
@user
=
create
:user
{
@opts
=
{
name:
"GitLab"
,
name:
"GitLab"
,
namespace:
user
.
namespace
namespace:
@user
.
namespace
}
}
end
end
it
'creates labels on Project creation if there are templates'
do
it
'creates labels on Project creation if there are templates'
do
Label
.
create
(
title:
"bug"
,
template:
true
)
Label
.
create
(
title:
"bug"
,
template:
true
)
project
=
create_project
(
@user
,
@opts
)
project
=
create_project
(
user
,
opts
)
project
.
reload
expect
(
project
.
labels
).
not_to
be_empty
expect
(
project
.
labels
).
not_to
be_empty
end
end
context
'user namespace'
do
context
'user namespace'
do
before
do
it
do
@project
=
create_project
(
@user
,
@opts
)
project
=
create_project
(
user
,
opts
)
end
it
{
expect
(
@project
).
to
be_valid
}
expect
(
project
).
to
be_valid
it
{
expect
(
@project
.
owner
).
to
eq
(
@user
)
}
expect
(
project
.
owner
).
to
eq
(
user
)
it
{
expect
(
@project
.
team
.
masters
).
to
include
(
@user
)
}
expect
(
project
.
team
.
masters
).
to
include
(
user
)
it
{
expect
(
@project
.
namespace
).
to
eq
(
@user
.
namespace
)
}
expect
(
project
.
namespace
).
to
eq
(
user
.
namespace
)
end
end
end
context
'group namespace'
do
context
'group namespace'
do
before
do
let
(
:group
)
do
@group
=
create
:group
create
(
:group
).
tap
do
|
group
|
@group
.
add_owner
(
@user
)
group
.
add_owner
(
user
)
end
end
@user
.
refresh_authorized_projects
# Ensure cache is warm
before
do
user
.
refresh_authorized_projects
# Ensure cache is warm
end
@opts
.
merge!
(
namespace_id:
@group
.
id
)
it
do
@project
=
create_project
(
@user
,
@opts
)
project
=
create_project
(
user
,
opts
.
merge!
(
namespace_id:
group
.
id
))
end
it
{
expect
(
@project
).
to
be_valid
}
expect
(
project
).
to
be_valid
it
{
expect
(
@project
.
owner
).
to
eq
(
@group
)
}
expect
(
project
.
owner
).
to
eq
(
group
)
it
{
expect
(
@project
.
namespace
).
to
eq
(
@group
)
}
expect
(
project
.
namespace
).
to
eq
(
group
)
it
{
expect
(
@user
.
authorized_projects
).
to
include
(
@project
)
}
expect
(
user
.
authorized_projects
).
to
include
(
project
)
end
end
end
context
'error handling'
do
context
'error handling'
do
it
'handles invalid options'
do
it
'handles invalid options'
do
@opts
.
merge!
({
default_branch:
'master'
}
)
opts
.
merge!
({
default_branch:
'master'
}
)
expect
(
create_project
(
@user
,
@opts
)).
to
eq
(
nil
)
expect
(
create_project
(
user
,
opts
)).
to
eq
(
nil
)
end
end
end
end
context
'wiki_enabled creates repository directory'
do
context
'wiki_enabled creates repository directory'
do
context
'wiki_enabled true creates wiki repository directory'
do
context
'wiki_enabled true creates wiki repository directory'
do
before
do
it
do
@project
=
create_project
(
@user
,
@opts
)
project
=
create_project
(
user
,
opts
)
@path
=
ProjectWiki
.
new
(
@project
,
@user
).
send
(
:path_to_repo
)
path
=
ProjectWiki
.
new
(
project
,
user
).
send
(
:path_to_repo
)
end
it
{
expect
(
File
.
exist?
(
@path
)).
to
be_truthy
}
expect
(
File
.
exist?
(
path
)).
to
be_truthy
end
end
end
context
'wiki_enabled false does not create wiki repository directory'
do
context
'wiki_enabled false does not create wiki repository directory'
do
before
do
it
do
@opts
.
merge!
(
wiki_enabled:
false
)
opts
.
merge!
(
wiki_enabled:
false
)
@project
=
create_project
(
@user
,
@opts
)
project
=
create_project
(
user
,
opts
)
@path
=
ProjectWiki
.
new
(
@project
,
@user
).
send
(
:path_to_repo
)
path
=
ProjectWiki
.
new
(
project
,
user
).
send
(
:path_to_repo
)
end
it
{
expect
(
File
.
exist?
(
@path
)).
to
be_falsey
}
expect
(
File
.
exist?
(
path
)).
to
be_falsey
end
end
end
end
end
context
'builds_enabled global setting'
do
context
'builds_enabled global setting'
do
let
(
:project
)
{
create_project
(
@user
,
@opts
)
}
let
(
:project
)
{
create_project
(
user
,
opts
)
}
subject
{
project
.
builds_enabled?
}
context
'global builds_enabled false does not enable CI by default'
do
subject
{
project
.
builds_enabled?
}
before
do
project
.
project_feature
.
update_attribute
(
:builds_access_level
,
ProjectFeature
::
DISABLED
)
end
it
{
is_expected
.
to
be_falsey
}
context
'global builds_enabled false does not enable CI by default'
do
before
do
project
.
project_feature
.
update_attribute
(
:builds_access_level
,
ProjectFeature
::
DISABLED
)
end
end
context
'global builds_enabled true does enable CI by default'
do
it
{
is_expected
.
to
be_falsey
}
before
do
end
project
.
project_feature
.
update_attribute
(
:builds_access_level
,
ProjectFeature
::
ENABLED
)
end
it
{
is_expected
.
to
be_truthy
}
context
'global builds_enabled true does enable CI by default'
do
before
do
project
.
project_feature
.
update_attribute
(
:builds_access_level
,
ProjectFeature
::
ENABLED
)
end
end
it
{
is_expected
.
to
be_truthy
}
end
end
end
context
'restricted visibility level'
do
context
'restricted visibility level'
do
before
do
before
do
stub_application_setting
(
restricted_visibility_levels:
[
Gitlab
::
VisibilityLevel
::
PUBLIC
])
stub_application_setting
(
restricted_visibility_levels:
[
Gitlab
::
VisibilityLevel
::
PUBLIC
])
@
opts
.
merge!
(
opts
.
merge!
(
visibility_level:
Gitlab
::
VisibilityLevel
.
options
[
'Public'
]
visibility_level:
Gitlab
::
VisibilityLevel
.
options
[
'Public'
]
)
)
end
end
it
'does not allow a restricted visibility level for non-admins'
do
it
'does not allow a restricted visibility level for non-admins'
do
project
=
create_project
(
@user
,
@
opts
)
project
=
create_project
(
user
,
opts
)
expect
(
project
).
to
respond_to
(
:errors
)
expect
(
project
).
to
respond_to
(
:errors
)
expect
(
project
.
errors
.
messages
).
to
have_key
(
:visibility_level
)
expect
(
project
.
errors
.
messages
).
to
have_key
(
:visibility_level
)
expect
(
project
.
errors
.
messages
[
:visibility_level
].
first
).
to
(
expect
(
project
.
errors
.
messages
[
:visibility_level
].
first
).
to
(
match
(
'restricted by your GitLab administrator'
)
match
(
'restricted by your GitLab administrator'
)
)
)
end
end
it
'allows a restricted visibility level for admins'
do
it
'allows a restricted visibility level for admins'
do
admin
=
create
(
:admin
)
admin
=
create
(
:admin
)
project
=
create_project
(
admin
,
@
opts
)
project
=
create_project
(
admin
,
opts
)
expect
(
project
.
errors
.
any?
).
to
be
(
false
)
expect
(
project
.
errors
.
any?
).
to
be
(
false
)
expect
(
project
.
saved?
).
to
be
(
true
)
expect
(
project
.
saved?
).
to
be
(
true
)
end
end
end
end
context
'repository creation'
do
context
'repository creation'
do
it
'synchronously creates the repository'
do
it
'synchronously creates the repository'
do
expect_any_instance_of
(
Project
).
to
receive
(
:create_repository
)
expect_any_instance_of
(
Project
).
to
receive
(
:create_repository
)
project
=
create_project
(
@user
,
@opts
)
project
=
create_project
(
user
,
opts
)
expect
(
project
).
to
be_valid
expect
(
project
).
to
be_valid
expect
(
project
.
owner
).
to
eq
(
@user
)
expect
(
project
.
owner
).
to
eq
(
user
)
expect
(
project
.
namespace
).
to
eq
(
@user
.
namespace
)
expect
(
project
.
namespace
).
to
eq
(
user
.
namespace
)
end
end
end
end
context
'when there is an active service template'
do
context
'when there is an active service template'
do
before
do
before
do
create
(
:service
,
project:
nil
,
template:
true
,
active:
true
)
create
(
:service
,
project:
nil
,
template:
true
,
active:
true
)
end
end
it
'creates a service from this template'
do
it
'creates a service from this template'
do
project
=
create_project
(
@user
,
@opts
)
project
=
create_project
(
user
,
opts
)
project
.
reload
expect
(
project
.
services
.
count
).
to
eq
1
expect
(
project
.
services
.
count
).
to
eq
1
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