Commit a7f6ab95 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '39601-create-issuable-destroy-service' into 'master'

Create issue and merge request destroy services

Closes #39601

See merge request gitlab-org/gitlab-ce!15604
parents 24fadd7c 7fb1bb01
...@@ -54,7 +54,7 @@ module IssuableActions ...@@ -54,7 +54,7 @@ module IssuableActions
end end
def destroy def destroy
issuable.destroy Issuable::DestroyService.new(project, current_user).execute(issuable)
TodoService.new.destroy_issuable(issuable, current_user) TodoService.new.destroy_issuable(issuable, current_user)
name = issuable.human_class_name name = issuable.human_class_name
......
...@@ -49,7 +49,6 @@ class Issue < ActiveRecord::Base ...@@ -49,7 +49,6 @@ class Issue < ActiveRecord::Base
scope :public_only, -> { where(confidential: false) } scope :public_only, -> { where(confidential: false) }
after_save :expire_etag_cache after_save :expire_etag_cache
after_commit :update_project_counter_caches, on: :destroy
attr_spammable :title, spam_title: true attr_spammable :title, spam_title: true
attr_spammable :description, spam_description: true attr_spammable :description, spam_description: true
......
...@@ -52,7 +52,6 @@ class MergeRequest < ActiveRecord::Base ...@@ -52,7 +52,6 @@ class MergeRequest < ActiveRecord::Base
after_create :ensure_merge_request_diff, unless: :importing? after_create :ensure_merge_request_diff, unless: :importing?
after_update :reload_diff_if_branch_changed after_update :reload_diff_if_branch_changed
after_commit :update_project_counter_caches, on: :destroy
# When this attribute is true some MR validation is ignored # When this attribute is true some MR validation is ignored
# It allows us to close or modify broken merge requests # It allows us to close or modify broken merge requests
......
module Issuable
class DestroyService < IssuableBaseService
def execute(issuable)
if issuable.destroy
issuable.update_project_counter_caches
end
end
end
end
---
title: Create issuable destroy service
merge_request: 15604
author: George Andrinopoulos
type: other
...@@ -255,7 +255,9 @@ module API ...@@ -255,7 +255,9 @@ module API
authorize!(:destroy_issue, issue) authorize!(:destroy_issue, issue)
destroy_conditionally!(issue) destroy_conditionally!(issue) do |issue|
Issuable::DestroyService.new(user_project, current_user).execute(issue)
end
end end
desc 'List merge requests closing issue' do desc 'List merge requests closing issue' do
......
...@@ -167,7 +167,9 @@ module API ...@@ -167,7 +167,9 @@ module API
authorize!(:destroy_merge_request, merge_request) authorize!(:destroy_merge_request, merge_request)
destroy_conditionally!(merge_request) destroy_conditionally!(merge_request) do |merge_request|
Issuable::DestroyService.new(user_project, current_user).execute(merge_request)
end
end end
params do params do
......
require 'spec_helper'
describe Issuable::DestroyService do
let(:user) { create(:user) }
let(:project) { create(:project) }
subject(:service) { described_class.new(project, user) }
describe '#execute' do
context 'when issuable is an issue' do
let!(:issue) { create(:issue, project: project, author: user) }
it 'destroys the issue' do
expect { service.execute(issue) }.to change { project.issues.count }.by(-1)
end
it 'updates open issues count cache' do
expect_any_instance_of(Projects::OpenIssuesCountService).to receive(:refresh_cache)
service.execute(issue)
end
end
context 'when issuable is a merge request' do
let!(:merge_request) { create(:merge_request, target_project: project, source_project: project, author: user) }
it 'destroys the merge request' do
expect { service.execute(merge_request) }.to change { project.merge_requests.count }.by(-1)
end
it 'updates open merge requests count cache' do
expect_any_instance_of(Projects::OpenMergeRequestsCountService).to receive(:refresh_cache)
service.execute(merge_request)
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