Commit b263c117 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Use RelatedIssues::DestroyService on destroy action

parent d5993408
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!
......
...@@ -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
......
...@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment