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
5780df0f
Commit
5780df0f
authored
May 04, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return related issues after create and destroy interactions
parent
cf2ec7d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
9 deletions
+30
-9
app/controllers/projects/related_issues_controller.rb
app/controllers/projects/related_issues_controller.rb
+11
-3
spec/controllers/projects/related_issues_controller_spec.rb
spec/controllers/projects/related_issues_controller_spec.rb
+19
-6
No files found.
app/controllers/projects/related_issues_controller.rb
View file @
5780df0f
...
@@ -4,14 +4,18 @@ module Projects
...
@@ -4,14 +4,18 @@ module Projects
before_action
:authorize_admin_related_issue!
,
only:
[
:create
,
:destroy
]
before_action
:authorize_admin_related_issue!
,
only:
[
:create
,
:destroy
]
def
index
def
index
render
json:
RelatedIssues
::
ListService
.
new
(
issue
,
current_user
).
execute
render
json:
issues
end
end
def
create
def
create
opts
=
{
issue_references:
params
[
:issue_references
]
}
opts
=
{
issue_references:
params
[
:issue_references
]
}
result
=
RelatedIssues
::
CreateService
.
new
(
issue
,
current_user
,
opts
).
execute
result
=
RelatedIssues
::
CreateService
.
new
(
issue
,
current_user
,
opts
).
execute
render
json:
result
,
status:
result
[
'http_status'
]
if
result
[
'status'
]
==
'success'
render
json:
{
result:
result
,
issues:
issues
},
status:
result
[
'http_status'
]
else
render
json:
{
result:
result
},
status:
result
[
'http_status'
]
end
end
end
def
destroy
def
destroy
...
@@ -23,11 +27,15 @@ module Projects
...
@@ -23,11 +27,15 @@ module Projects
result
=
RelatedIssues
::
DestroyService
.
new
(
related_issue
,
current_user
).
execute
result
=
RelatedIssues
::
DestroyService
.
new
(
related_issue
,
current_user
).
execute
render
json:
result
render
json:
{
result:
result
,
issues:
issues
}
end
end
private
private
def
issues
RelatedIssues
::
ListService
.
new
(
issue
,
current_user
).
execute
end
def
authorize_admin_related_issue!
def
authorize_admin_related_issue!
return
render_404
unless
can?
(
current_user
,
:admin_related_issue
,
@project
)
return
render_404
unless
can?
(
current_user
,
:admin_related_issue
,
@project
)
end
end
...
...
spec/controllers/projects/related_issues_controller_spec.rb
View file @
5780df0f
...
@@ -33,7 +33,9 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -33,7 +33,9 @@ describe Projects::RelatedIssuesController, type: :controller do
describe
'POST #create'
do
describe
'POST #create'
do
let
(
:service
)
{
double
(
RelatedIssues
::
CreateService
,
execute:
service_response
)
}
let
(
:service
)
{
double
(
RelatedIssues
::
CreateService
,
execute:
service_response
)
}
let
(
:service_response
)
{
{
'message'
=>
'yay'
}
}
let
(
:list_service
)
{
double
(
RelatedIssues
::
ListService
,
execute:
list_service_response
)
}
let
(
:service_response
)
{
{
'message'
=>
'yay'
,
'status'
=>
'success'
}
}
let
(
:list_service_response
)
{
[{
'foo'
=>
'bar'
}]
}
let
(
:issue_references
)
{
double
}
let
(
:issue_references
)
{
double
}
let
(
:user_role
)
{
:developer
}
let
(
:user_role
)
{
:developer
}
...
@@ -41,6 +43,10 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -41,6 +43,10 @@ describe Projects::RelatedIssuesController, type: :controller do
project
.
team
<<
[
user
,
user_role
]
project
.
team
<<
[
user
,
user_role
]
sign_in
user
sign_in
user
allow
(
RelatedIssues
::
ListService
).
to
receive
(
:new
)
.
with
(
issue
,
user
)
.
and_return
(
list_service
)
allow
(
RelatedIssues
::
CreateService
).
to
receive
(
:new
)
allow
(
RelatedIssues
::
CreateService
).
to
receive
(
:new
)
.
with
(
issue
,
user
,
{
issue_references:
issue_references
})
.
with
(
issue
,
user
,
{
issue_references:
issue_references
})
.
and_return
(
service
)
.
and_return
(
service
)
...
@@ -57,7 +63,8 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -57,7 +63,8 @@ describe Projects::RelatedIssuesController, type: :controller do
context
'with success'
do
context
'with success'
do
it
'returns success JSON'
do
it
'returns success JSON'
do
is_expected
.
to
have_http_status
(
200
)
is_expected
.
to
have_http_status
(
200
)
expect
(
json_response
).
to
eq
(
service_response
)
expect
(
json_response
).
to
eq
(
'result'
=>
service_response
,
'issues'
=>
list_service_response
)
end
end
end
end
...
@@ -70,12 +77,12 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -70,12 +77,12 @@ describe Projects::RelatedIssuesController, type: :controller do
end
end
end
end
context
'when fail
ure
service result'
do
context
'when fail
ing
service result'
do
let
(
:service_response
)
{
{
'http_status'
=>
401
}
}
let
(
:service_response
)
{
{
'http_status'
=>
401
,
'status'
=>
'error'
}
}
it
'returns failure JSON'
do
it
'returns failure JSON'
do
is_expected
.
to
have_http_status
(
401
)
is_expected
.
to
have_http_status
(
401
)
expect
(
json_response
).
to
eq
(
service_response
)
expect
(
json_response
).
to
eq
(
'result'
=>
service_response
)
end
end
end
end
end
end
...
@@ -85,7 +92,9 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -85,7 +92,9 @@ describe Projects::RelatedIssuesController, type: :controller do
let
(
:referenced_issue
)
{
create
:issue
,
project:
project
}
let
(
:referenced_issue
)
{
create
:issue
,
project:
project
}
let
(
:related_issue
)
{
create
:related_issue
,
related_issue:
referenced_issue
}
let
(
:related_issue
)
{
create
:related_issue
,
related_issue:
referenced_issue
}
let
(
:service
)
{
double
(
RelatedIssues
::
DestroyService
,
execute:
service_response
)
}
let
(
:service
)
{
double
(
RelatedIssues
::
DestroyService
,
execute:
service_response
)
}
let
(
:list_service
)
{
double
(
RelatedIssues
::
ListService
,
execute:
list_service_response
)
}
let
(
:service_response
)
{
{
'message'
=>
'yay'
}
}
let
(
:service_response
)
{
{
'message'
=>
'yay'
}
}
let
(
:list_service_response
)
{
[{
'foo'
=>
'bar'
}]
}
let
(
:current_project_user_role
)
{
:developer
}
let
(
:current_project_user_role
)
{
:developer
}
subject
do
subject
do
...
@@ -100,6 +109,10 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -100,6 +109,10 @@ describe Projects::RelatedIssuesController, type: :controller do
project
.
team
<<
[
user
,
current_project_user_role
]
project
.
team
<<
[
user
,
current_project_user_role
]
sign_in
user
sign_in
user
allow
(
RelatedIssues
::
ListService
).
to
receive
(
:new
)
.
with
(
issue
,
user
)
.
and_return
(
list_service
)
allow
(
RelatedIssues
::
DestroyService
).
to
receive
(
:new
)
allow
(
RelatedIssues
::
DestroyService
).
to
receive
(
:new
)
.
with
(
related_issue
,
user
)
.
with
(
related_issue
,
user
)
.
and_return
(
service
)
.
and_return
(
service
)
...
@@ -129,7 +142,7 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -129,7 +142,7 @@ describe Projects::RelatedIssuesController, type: :controller do
it
'returns success JSON'
do
it
'returns success JSON'
do
is_expected
.
to
have_http_status
(
200
)
is_expected
.
to
have_http_status
(
200
)
expect
(
json_response
).
to
eq
(
service_response
)
expect
(
json_response
).
to
eq
(
'result'
=>
service_response
,
'issues'
=>
list_
service_response
)
end
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