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
Léo-Paul Géneau
gitlab-ce
Commits
2c2a1dea
Commit
2c2a1dea
authored
Oct 06, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring service to create a new issue in a board list
parent
81c253de
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
19 deletions
+26
-19
app/controllers/projects/boards/issues_controller.rb
app/controllers/projects/boards/issues_controller.rb
+2
-3
app/services/boards/issues/create_service.rb
app/services/boards/issues/create_service.rb
+11
-4
spec/controllers/projects/boards/issues_controller_spec.rb
spec/controllers/projects/boards/issues_controller_spec.rb
+7
-6
spec/services/boards/issues/create_service_spec.rb
spec/services/boards/issues/create_service_spec.rb
+6
-6
No files found.
app/controllers/projects/boards/issues_controller.rb
View file @
2c2a1dea
...
@@ -16,9 +16,8 @@ module Projects
...
@@ -16,9 +16,8 @@ module Projects
end
end
def
create
def
create
list
=
project
.
board
.
lists
.
find
(
params
[
:list_id
])
service
=
::
Boards
::
Issues
::
CreateService
.
new
(
project
,
current_user
,
issue_params
)
service
=
::
Boards
::
Issues
::
CreateService
.
new
(
project
,
current_user
,
issue_params
)
issue
=
service
.
execute
(
list
)
issue
=
service
.
execute
if
issue
.
valid?
if
issue
.
valid?
render
json:
serialize_as_json
(
issue
)
render
json:
serialize_as_json
(
issue
)
...
@@ -68,7 +67,7 @@ module Projects
...
@@ -68,7 +67,7 @@ module Projects
end
end
def
issue_params
def
issue_params
params
.
require
(
:issue
).
permit
(
:title
).
merge
(
request:
request
)
params
.
require
(
:issue
).
permit
(
:title
).
merge
(
board_id:
params
[
:board_id
],
list_id:
params
[
:list_id
],
request:
request
)
end
end
def
serialize_as_json
(
resource
)
def
serialize_as_json
(
resource
)
...
...
app/services/boards/issues/create_service.rb
View file @
2c2a1dea
module
Boards
module
Boards
module
Issues
module
Issues
class
CreateService
<
Boards
::
BaseService
class
CreateService
<
Boards
::
BaseService
def
execute
(
list
)
def
execute
params
.
merge!
(
label_ids:
[
list
.
label_id
])
create_issue
(
params
.
merge
(
label_ids:
[
list
.
label_id
]))
create_issue
end
end
private
private
def
create_issue
def
board
@board
||=
project
.
boards
.
find
(
params
.
delete
(
:board_id
))
end
def
list
@list
||=
board
.
lists
.
find
(
params
.
delete
(
:list_id
))
end
def
create_issue
(
params
)
::
Issues
::
CreateService
.
new
(
project
,
current_user
,
params
).
execute
::
Issues
::
CreateService
.
new
(
project
,
current_user
,
params
).
execute
end
end
end
end
...
...
spec/controllers/projects/boards/issues_controller_spec.rb
View file @
2c2a1dea
...
@@ -76,13 +76,13 @@ describe Projects::Boards::IssuesController do
...
@@ -76,13 +76,13 @@ describe Projects::Boards::IssuesController do
describe
'POST create'
do
describe
'POST create'
do
context
'with valid params'
do
context
'with valid params'
do
it
'returns a successful 200 response'
do
it
'returns a successful 200 response'
do
create_issue
user:
user
,
list:
list1
,
title:
'New issue'
create_issue
user:
user
,
board:
board
,
list:
list1
,
title:
'New issue'
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
it
'returns the created issue'
do
it
'returns the created issue'
do
create_issue
user:
user
,
list:
list1
,
title:
'New issue'
create_issue
user:
user
,
board:
board
,
list:
list1
,
title:
'New issue'
expect
(
response
).
to
match_response_schema
(
'issue'
)
expect
(
response
).
to
match_response_schema
(
'issue'
)
end
end
...
@@ -91,7 +91,7 @@ describe Projects::Boards::IssuesController do
...
@@ -91,7 +91,7 @@ describe Projects::Boards::IssuesController do
context
'with invalid params'
do
context
'with invalid params'
do
context
'when title is nil'
do
context
'when title is nil'
do
it
'returns an unprocessable entity 422 response'
do
it
'returns an unprocessable entity 422 response'
do
create_issue
user:
user
,
list:
list1
,
title:
nil
create_issue
user:
user
,
board:
board
,
list:
list1
,
title:
nil
expect
(
response
).
to
have_http_status
(
422
)
expect
(
response
).
to
have_http_status
(
422
)
end
end
...
@@ -101,7 +101,7 @@ describe Projects::Boards::IssuesController do
...
@@ -101,7 +101,7 @@ describe Projects::Boards::IssuesController do
it
'returns a not found 404 response'
do
it
'returns a not found 404 response'
do
list
=
create
(
:list
)
list
=
create
(
:list
)
create_issue
user:
user
,
list:
list
,
title:
'New issue'
create_issue
user:
user
,
board:
board
,
list:
list
,
title:
'New issue'
expect
(
response
).
to
have_http_status
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
@@ -110,17 +110,18 @@ describe Projects::Boards::IssuesController do
...
@@ -110,17 +110,18 @@ describe Projects::Boards::IssuesController do
context
'with unauthorized user'
do
context
'with unauthorized user'
do
it
'returns a forbidden 403 response'
do
it
'returns a forbidden 403 response'
do
create_issue
user:
guest
,
list:
list1
,
title:
'New issue'
create_issue
user:
guest
,
board:
board
,
list:
list1
,
title:
'New issue'
expect
(
response
).
to
have_http_status
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
end
def
create_issue
(
user
:,
list
:,
title
:)
def
create_issue
(
user
:,
board
:,
list
:,
title
:)
sign_in
(
user
)
sign_in
(
user
)
post
:create
,
namespace_id:
project
.
namespace
.
to_param
,
post
:create
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
project_id:
project
.
to_param
,
board_id:
board
.
to_param
,
list_id:
list
.
to_param
,
list_id:
list
.
to_param
,
issue:
{
title:
title
},
issue:
{
title:
title
},
format: :json
format: :json
...
...
spec/services/boards/issues/create_service_spec.rb
View file @
2c2a1dea
...
@@ -2,13 +2,13 @@ require 'spec_helper'
...
@@ -2,13 +2,13 @@ require 'spec_helper'
describe
Boards
::
Issues
::
CreateService
,
services:
true
do
describe
Boards
::
Issues
::
CreateService
,
services:
true
do
describe
'#execute'
do
describe
'#execute'
do
let
(
:project
)
{
create
(
:
project_with_board
)
}
let
(
:project
)
{
create
(
:
empty_project
)
}
let
(
:board
)
{
project
.
board
}
let
(
:board
)
{
create
(
:board
,
project:
project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:label
)
{
create
(
:label
,
project:
project
,
name:
'in-progress'
)
}
let
(
:label
)
{
create
(
:label
,
project:
project
,
name:
'in-progress'
)
}
let!
(
:list
)
{
create
(
:list
,
board:
board
,
label:
label
,
position:
0
)
}
let!
(
:list
)
{
create
(
:list
,
board:
board
,
label:
label
,
position:
0
)
}
subject
(
:service
)
{
described_class
.
new
(
project
,
user
,
title:
'New issue'
)
}
subject
(
:service
)
{
described_class
.
new
(
project
,
user
,
board_id:
board
.
id
,
list_id:
list
.
id
,
title:
'New issue'
)
}
before
do
before
do
project
.
team
<<
[
user
,
:developer
]
project
.
team
<<
[
user
,
:developer
]
...
@@ -17,15 +17,15 @@ describe Boards::Issues::CreateService, services: true do
...
@@ -17,15 +17,15 @@ describe Boards::Issues::CreateService, services: true do
it
'delegates the create proceedings to Issues::CreateService'
do
it
'delegates the create proceedings to Issues::CreateService'
do
expect_any_instance_of
(
Issues
::
CreateService
).
to
receive
(
:execute
).
once
expect_any_instance_of
(
Issues
::
CreateService
).
to
receive
(
:execute
).
once
service
.
execute
(
list
)
service
.
execute
end
end
it
'creates a new issue'
do
it
'creates a new issue'
do
expect
{
service
.
execute
(
list
)
}.
to
change
(
project
.
issues
,
:count
).
by
(
1
)
expect
{
service
.
execute
}.
to
change
(
project
.
issues
,
:count
).
by
(
1
)
end
end
it
'adds the label of the list to the issue'
do
it
'adds the label of the list to the issue'
do
issue
=
service
.
execute
(
list
)
issue
=
service
.
execute
expect
(
issue
.
labels
).
to
eq
[
label
]
expect
(
issue
.
labels
).
to
eq
[
label
]
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