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
b263c117
Commit
b263c117
authored
Apr 26, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use RelatedIssues::DestroyService on destroy action
parent
d5993408
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
2 deletions
+50
-2
app/controllers/projects/related_issues_controller.rb
app/controllers/projects/related_issues_controller.rb
+8
-1
config/routes/project.rb
config/routes/project.rb
+1
-1
spec/controllers/projects/related_issues_controller_spec.rb
spec/controllers/projects/related_issues_controller_spec.rb
+41
-0
No files found.
app/controllers/projects/related_issues_controller.rb
View file @
b263c117
module
Projects
module
Projects
class
RelatedIssuesController
<
ApplicationController
class
RelatedIssuesController
<
ApplicationController
before_action
:authorize_read_related_issue!
before_action
:authorize_read_related_issue!
before_action
:authorize_admin_related_issue!
,
only:
[
:create
]
before_action
:authorize_admin_related_issue!
,
only:
[
:create
,
:destroy
]
def
index
def
index
render
json:
RelatedIssues
::
ListService
.
new
(
issue
,
current_user
).
execute
render
json:
RelatedIssues
::
ListService
.
new
(
issue
,
current_user
).
execute
...
@@ -14,6 +14,13 @@ module Projects
...
@@ -14,6 +14,13 @@ module Projects
render
json:
result
,
status:
result
[
'http_status'
]
render
json:
result
,
status:
result
[
'http_status'
]
end
end
def
destroy
related_issue
=
RelatedIssue
.
find
(
params
[
:id
])
result
=
RelatedIssues
::
DestroyService
.
new
(
related_issue
,
current_user
).
execute
render
json:
result
end
private
private
def
authorize_admin_related_issue!
def
authorize_admin_related_issue!
...
...
config/routes/project.rb
View file @
b263c117
...
@@ -312,7 +312,7 @@ constraints(ProjectUrlConstrainer.new) do
...
@@ -312,7 +312,7 @@ constraints(ProjectUrlConstrainer.new) do
post
:export_csv
post
:export_csv
end
end
resources
:related_issues
,
only:
[
:index
,
:create
]
resources
:related_issues
,
only:
[
:index
,
:create
,
:destroy
]
end
end
resources
:project_members
,
except:
[
:show
,
:new
,
:edit
],
constraints:
{
id:
/[a-zA-Z.\/0-9_\-#%+]+/
},
concerns: :access_requestable
do
resources
:project_members
,
except:
[
:show
,
:new
,
:edit
],
constraints:
{
id:
/[a-zA-Z.\/0-9_\-#%+]+/
},
concerns: :access_requestable
do
...
...
spec/controllers/projects/related_issues_controller_spec.rb
View file @
b263c117
...
@@ -80,4 +80,45 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -80,4 +80,45 @@ describe Projects::RelatedIssuesController, type: :controller do
end
end
end
end
end
end
describe
'DELETE #destroy'
do
let
(
:related_issue
)
{
create
:related_issue
}
let
(
:service
)
{
double
(
RelatedIssues
::
DestroyService
,
execute:
service_response
)
}
let
(
:service_response
)
{
{
'message'
=>
'yay'
}
}
let
(
:user_role
)
{
:developer
}
subject
do
delete
:destroy
,
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
id:
related_issue
,
format: :json
end
before
do
project
.
team
<<
[
user
,
user_role
]
sign_in
user
allow
(
RelatedIssues
::
DestroyService
).
to
receive
(
:new
)
.
with
(
related_issue
,
user
)
.
and_return
(
service
)
end
context
'when unauthorized'
do
let
(
:user_role
)
{
:guest
}
it
'returns 404'
do
is_expected
.
to
have_http_status
(
404
)
end
end
context
'when authorized'
do
let
(
:user_role
)
{
:developer
}
it
'returns success JSON'
do
is_expected
.
to
have_http_status
(
200
)
expect
(
json_response
).
to
eq
(
service_response
)
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