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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
6c189dcc
Commit
6c189dcc
authored
Oct 18, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add service to create project labels
parent
49ec98d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
app/services/labels/create_service.rb
app/services/labels/create_service.rb
+33
-0
spec/services/labels/create_service_spec.rb
spec/services/labels/create_service_spec.rb
+51
-0
No files found.
app/services/labels/create_service.rb
0 → 100644
View file @
6c189dcc
module
Labels
class
CreateService
def
initialize
(
current_user
,
project
,
params
=
{})
@current_user
=
current_user
@group
=
project
.
group
@project
=
project
@params
=
params
.
dup
end
def
execute
find_or_create_label
end
private
attr_reader
:current_user
,
:group
,
:project
,
:params
def
available_labels
@available_labels
||=
LabelsFinder
.
new
(
current_user
,
project_id:
project
.
id
).
execute
end
def
find_or_create_label
new_label
=
available_labels
.
find_by
(
title:
title
)
new_label
||=
project
.
labels
.
create
(
params
)
new_label
end
def
title
params
[
:title
]
||
params
[
:name
]
end
end
end
spec/services/labels/create_service_spec.rb
0 → 100644
View file @
6c189dcc
require
'spec_helper'
describe
Labels
::
CreateService
,
services:
true
do
describe
'#execute'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
let
(
:params
)
do
{
title:
'Security'
,
description:
'Security related stuff.'
,
color:
'#FF0000'
}
end
subject
(
:service
)
{
described_class
.
new
(
user
,
project
,
params
)
}
before
do
project
.
team
<<
[
user
,
:developer
]
end
context
'when label does not exist at group level'
do
it
'creates a new label at project level'
do
expect
{
service
.
execute
}.
to
change
(
project
.
labels
,
:count
).
by
(
1
)
end
end
context
'when label exists at group level'
do
it
'returns the group label'
do
group_label
=
create
(
:group_label
,
group:
group
,
title:
'Security'
)
expect
(
service
.
execute
).
to
eq
group_label
end
end
context
'when label does not exist at group level'
do
it
'creates a new label at project leve'
do
expect
{
service
.
execute
}.
to
change
(
project
.
labels
,
:count
).
by
(
1
)
end
end
context
'when label exists at project level'
do
it
'returns the project label'
do
project_label
=
create
(
:label
,
project:
project
,
title:
'Security'
)
expect
(
service
.
execute
).
to
eq
project_label
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