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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
d86c6666
Commit
d86c6666
authored
Sep 01, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refresh todos count cache when an Issue/MR is deleted
parent
796bdf1d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
0 deletions
+50
-0
app/controllers/concerns/issuable_actions.rb
app/controllers/concerns/issuable_actions.rb
+2
-0
app/services/todo_service.rb
app/services/todo_service.rb
+20
-0
spec/controllers/projects/issues_controller_spec.rb
spec/controllers/projects/issues_controller_spec.rb
+6
-0
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+6
-0
spec/services/todo_service_spec.rb
spec/services/todo_service_spec.rb
+16
-0
No files found.
app/controllers/concerns/issuable_actions.rb
View file @
d86c6666
...
...
@@ -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."
...
...
app/services/todo_service.rb
View file @
d86c6666
...
...
@@ -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?
...
...
spec/controllers/projects/issues_controller_spec.rb
View file @
d86c6666
...
...
@@ -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
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
d86c6666
...
...
@@ -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
...
...
spec/services/todo_service_spec.rb
View file @
d86c6666
...
...
@@ -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
)
...
...
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