summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-09-09 09:57:31 +0000
committerRémy Coutable <remy@rymai.me>2016-09-09 09:57:31 +0000
commit12cc675ceb2c52b3f39260b807e48be91edb598c (patch)
tree7ad47dd5db0e64a9714a273edcede8ac33d359e5
parentcf76776d03885c02b58df07dbca42bc455f4a841 (diff)
parent28e6bb39de56376fc4672ffc41927d63ad2f2440 (diff)
downloadgitlab-ce-12cc675ceb2c52b3f39260b807e48be91edb598c.tar.gz
Merge branch '21714-refresh-the-todos-count-cache-after-issuable-delete' into 'master'
Refresh todos count cache when an Issue/MR is deleted Fixes #21714 See merge request !6161
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/concerns/issuable_actions.rb2
-rw-r--r--app/services/todo_service.rb20
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb6
-rw-r--r--spec/controllers/projects/merge_requests_controller_spec.rb6
-rw-r--r--spec/services/todo_service_spec.rb16
6 files changed, 51 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 4d1bb29a0b2..f528ca074fa 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -32,6 +32,7 @@ v 8.12.0 (unreleased)
- Fix project visibility level fields on settings
- Add hover color to emoji icon (ClemMakesApps)
- Add textarea autoresize after comment (ClemMakesApps)
+ - Refresh todos count cache when an Issue/MR is deleted
- Fix branches page dropdown sort alignment (ClemMakesApps)
- Add white background for no readme container (ClemMakesApps)
- API: Expose issue confidentiality flag. (Robert Schilling)
diff --git a/app/controllers/concerns/issuable_actions.rb b/app/controllers/concerns/issuable_actions.rb
index 77b4efffd7f..bb32bc502e6 100644
--- a/app/controllers/concerns/issuable_actions.rb
+++ b/app/controllers/concerns/issuable_actions.rb
@@ -8,6 +8,8 @@ module IssuableActions
def destroy
issuable.destroy
+ destroy_method = "destroy_#{issuable.class.name.underscore}".to_sym
+ TodoService.new.public_send(destroy_method, issuable, current_user)
name = issuable.class.name.titleize.downcase
flash[:notice] = "The #{name} was successfully deleted."
diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb
index 2aab8c736d6..776530ac0a5 100644
--- a/app/services/todo_service.rb
+++ b/app/services/todo_service.rb
@@ -31,6 +31,14 @@ class TodoService
mark_pending_todos_as_done(issue, current_user)
end
+ # When we destroy an issue we should:
+ #
+ # * refresh the todos count cache for the current user
+ #
+ def destroy_issue(issue, current_user)
+ destroy_issuable(issue, current_user)
+ end
+
# When we reassign an issue we should:
#
# * create a pending todo for new assignee if issue is assigned
@@ -64,6 +72,14 @@ class TodoService
mark_pending_todos_as_done(merge_request, current_user)
end
+ # When we destroy a merge request we should:
+ #
+ # * refresh the todos count cache for the current user
+ #
+ def destroy_merge_request(merge_request, current_user)
+ destroy_issuable(merge_request, current_user)
+ end
+
# When we reassign a merge request we should:
#
# * creates a pending todo for new assignee if merge request is assigned
@@ -187,6 +203,10 @@ class TodoService
create_mention_todos(issuable.project, issuable, author)
end
+ def destroy_issuable(issuable, user)
+ user.update_todos_count_cache
+ end
+
def toggling_tasks?(issuable)
issuable.previous_changes.include?('description') &&
issuable.tasks? && issuable.updated_tasks.any?
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index 16929767ddf..90419368f22 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -370,6 +370,12 @@ describe Projects::IssuesController do
expect(response).to have_http_status(302)
expect(controller).to set_flash[:notice].to(/The issue was successfully deleted\./).now
end
+
+ it 'delegates the update of the todos count cache to TodoService' do
+ expect_any_instance_of(TodoService).to receive(:destroy_issue).with(issue, owner).once
+
+ delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: issue.iid
+ end
end
end
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb
index a219400d75f..94c9edc91fe 100644
--- a/spec/controllers/projects/merge_requests_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests_controller_spec.rb
@@ -320,6 +320,12 @@ describe Projects::MergeRequestsController do
expect(response).to have_http_status(302)
expect(controller).to set_flash[:notice].to(/The merge request was successfully deleted\./).now
end
+
+ it 'delegates the update of the todos count cache to TodoService' do
+ expect_any_instance_of(TodoService).to receive(:destroy_merge_request).with(merge_request, owner).once
+
+ delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: merge_request.iid
+ end
end
end
diff --git a/spec/services/todo_service_spec.rb b/spec/services/todo_service_spec.rb
index cafcad3e3c0..b41f6f14fbd 100644
--- a/spec/services/todo_service_spec.rb
+++ b/spec/services/todo_service_spec.rb
@@ -145,6 +145,14 @@ describe TodoService, services: true do
end
end
+ describe '#destroy_issue' do
+ it 'refresh the todos count cache for the user' do
+ expect(john_doe).to receive(:update_todos_count_cache).and_call_original
+
+ service.destroy_issue(issue, john_doe)
+ end
+ end
+
describe '#reassigned_issue' do
it 'creates a pending todo for new assignee' do
unassigned_issue.update_attribute(:assignee, john_doe)
@@ -394,6 +402,14 @@ describe TodoService, services: true do
end
end
+ describe '#destroy_merge_request' do
+ it 'refresh the todos count cache for the user' do
+ expect(john_doe).to receive(:update_todos_count_cache).and_call_original
+
+ service.destroy_merge_request(mr_assigned, john_doe)
+ end
+ end
+
describe '#reassigned_merge_request' do
it 'creates a pending todo for new assignee' do
mr_unassigned.update_attribute(:assignee, john_doe)