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
7ef44a97
Commit
7ef44a97
authored
May 28, 2020
by
Pavel Shutsin
Committed by
Robert Speicher
May 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add resolution mechanism for todos
It will be used for internal research
parent
c2a32118
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
176 additions
and
225 deletions
+176
-225
app/controllers/dashboard/todos_controller.rb
app/controllers/dashboard/todos_controller.rb
+6
-4
app/graphql/mutations/todos/mark_all_done.rb
app/graphql/mutations/todos/mark_all_done.rb
+3
-1
app/graphql/mutations/todos/mark_done.rb
app/graphql/mutations/todos/mark_done.rb
+1
-1
app/graphql/mutations/todos/restore.rb
app/graphql/mutations/todos/restore.rb
+3
-3
app/graphql/mutations/todos/restore_many.rb
app/graphql/mutations/todos/restore_many.rb
+1
-1
app/models/todo.rb
app/models/todo.rb
+8
-6
app/models/user.rb
app/models/user.rb
+0
-4
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+1
-1
app/services/issues/update_service.rb
app/services/issues/update_service.rb
+2
-2
app/services/merge_requests/update_service.rb
app/services/merge_requests/update_service.rb
+2
-2
app/services/todo_service.rb
app/services/todo_service.rb
+36
-52
changelogs/unreleased/216045-capture-todo-resolution.yml
changelogs/unreleased/216045-capture-todo-resolution.yml
+5
-0
db/migrate/20200520103514_add_todo_resolved_by_action.rb
db/migrate/20200520103514_add_todo_resolved_by_action.rb
+19
-0
db/structure.sql
db/structure.sql
+3
-1
ee/app/services/epics/update_service.rb
ee/app/services/epics/update_service.rb
+2
-2
ee/app/services/merge_requests/approval_service.rb
ee/app/services/merge_requests/approval_service.rb
+1
-1
lib/api/todos.rb
lib/api/todos.rb
+4
-2
spec/features/dashboard/todos/todos_spec.rb
spec/features/dashboard/todos/todos_spec.rb
+1
-1
spec/models/todo_spec.rb
spec/models/todo_spec.rb
+4
-4
spec/services/todo_service_spec.rb
spec/services/todo_service_spec.rb
+74
-137
No files found.
app/controllers/dashboard/todos_controller.rb
View file @
7ef44a97
...
...
@@ -17,7 +17,9 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end
def
destroy
TodoService
.
new
.
mark_todos_as_done_by_ids
(
params
[
:id
],
current_user
)
todo
=
current_user
.
todos
.
find
(
params
[
:id
])
TodoService
.
new
.
resolve_todo
(
todo
,
current_user
,
resolved_by_action: :mark_done
)
respond_to
do
|
format
|
format
.
html
do
...
...
@@ -31,7 +33,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end
def
destroy_all
updated_ids
=
TodoService
.
new
.
mark_todos_as_done
(
@todos
,
current_user
)
updated_ids
=
TodoService
.
new
.
resolve_todos
(
@todos
,
current_user
,
resolved_by_action: :mark_all_done
)
respond_to
do
|
format
|
format
.
html
{
redirect_to
dashboard_todos_path
,
status: :found
,
notice:
_
(
'Everything on your to-do list is marked as done.'
)
}
...
...
@@ -41,13 +43,13 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end
def
restore
TodoService
.
new
.
mark_todos_as_pending_by_ids
(
params
[
:id
]
,
current_user
)
TodoService
.
new
.
restore_todo
(
current_user
.
todos
.
find
(
params
[
:id
])
,
current_user
)
render
json:
todos_counts
end
def
bulk_restore
TodoService
.
new
.
mark_todos_as_pending_by_ids
(
params
[
:ids
]
,
current_user
)
TodoService
.
new
.
restore_todos
(
current_user
.
todos
.
for_ids
(
params
[
:ids
])
,
current_user
)
render
json:
todos_counts
end
...
...
app/graphql/mutations/todos/mark_all_done.rb
View file @
7ef44a97
...
...
@@ -28,7 +28,9 @@ module Mutations
def
mark_all_todos_done
return
[]
unless
current_user
TodoService
.
new
.
mark_all_todos_as_done_by_user
(
current_user
)
todos
=
TodosFinder
.
new
(
current_user
).
execute
TodoService
.
new
.
resolve_todos
(
todos
,
current_user
,
resolved_by_action: :api_all_done
)
end
end
end
...
...
app/graphql/mutations/todos/mark_done.rb
View file @
7ef44a97
...
...
@@ -30,7 +30,7 @@ module Mutations
private
def
mark_done
(
todo
)
TodoService
.
new
.
mark_todo_as_done
(
todo
,
current_user
)
TodoService
.
new
.
resolve_todo
(
todo
,
current_user
,
resolved_by_action: :api_done
)
end
end
end
...
...
app/graphql/mutations/todos/restore.rb
View file @
7ef44a97
...
...
@@ -18,7 +18,7 @@ module Mutations
def
resolve
(
id
:)
todo
=
authorized_find!
(
id:
id
)
restore
(
todo
.
id
)
if
todo
.
done?
restore
(
todo
)
{
todo:
todo
.
reset
,
...
...
@@ -28,8 +28,8 @@ module Mutations
private
def
restore
(
id
)
TodoService
.
new
.
mark_todos_as_pending_by_ids
([
id
]
,
current_user
)
def
restore
(
todo
)
TodoService
.
new
.
restore_todo
(
todo
,
current_user
)
end
end
end
...
...
app/graphql/mutations/todos/restore_many.rb
View file @
7ef44a97
...
...
@@ -68,7 +68,7 @@ module Mutations
end
def
restore
(
todos
)
TodoService
.
new
.
mark_todos_as_pending
(
todos
,
current_user
)
TodoService
.
new
.
restore_todos
(
todos
,
current_user
)
end
end
end
...
...
app/models/todo.rb
View file @
7ef44a97
...
...
@@ -66,6 +66,8 @@ class Todo < ApplicationRecord
scope
:with_entity_associations
,
->
{
preload
(
:target
,
:author
,
:note
,
group: :route
,
project:
[
:route
,
{
namespace: :route
}])
}
scope
:joins_issue_and_assignees
,
->
{
left_joins
(
issue: :assignees
)
}
enum
resolved_by_action:
{
system_done:
0
,
api_all_done:
1
,
api_done:
2
,
mark_all_done:
3
,
mark_done:
4
},
_prefix: :resolved_by
state_machine
:state
,
initial: :pending
do
event
:done
do
transition
[
:pending
]
=>
:done
...
...
@@ -100,17 +102,17 @@ class Todo < ApplicationRecord
state
.
nil?
?
exists?
(
target:
target
)
:
exists?
(
target:
target
,
state:
state
)
end
# Updates
the state
of a relation of todos to the new state.
# Updates
attributes
of a relation of todos to the new state.
#
# new_
state - The new state
of the todos.
# new_
attributes - The new attributes
of the todos.
#
# Returns an `Array` containing the IDs of the updated todos.
def
update_state
(
new_state
)
# Only update those that
are not really on tha
t state
base
=
where
.
not
(
state:
new_
state
).
except
(
:order
)
def
batch_update
(
**
new_attributes
)
# Only update those that
have differen
t state
base
=
where
.
not
(
state:
new_
attributes
[
:state
]
).
except
(
:order
)
ids
=
base
.
pluck
(
:id
)
base
.
update_all
(
state:
new_state
,
updated_at:
Time
.
current
)
base
.
update_all
(
new_attributes
.
merge
(
updated_at:
Time
.
current
)
)
ids
end
...
...
app/models/user.rb
View file @
7ef44a97
...
...
@@ -1630,10 +1630,6 @@ class User < ApplicationRecord
super
.
presence
||
build_user_detail
end
def
todos_limited_to
(
ids
)
todos
.
where
(
id:
ids
)
end
def
pending_todo_for
(
target
)
todos
.
find_by
(
target:
target
,
state: :pending
)
end
...
...
app/services/issuable_base_service.rb
View file @
7ef44a97
...
...
@@ -350,7 +350,7 @@ class IssuableBaseService < BaseService
todo_service
.
mark_todo
(
issuable
,
current_user
)
when
'done'
todo
=
TodosFinder
.
new
(
current_user
).
find_by
(
target:
issuable
)
todo_service
.
mark_todos_as_done_by_ids
(
todo
,
current_user
)
if
todo
todo_service
.
resolve_todo
(
todo
,
current_user
)
if
todo
end
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
app/services/issues/update_service.rb
View file @
7ef44a97
...
...
@@ -32,7 +32,7 @@ module Issues
old_assignees
=
old_associations
.
fetch
(
:assignees
,
[])
if
has_changes?
(
issue
,
old_labels:
old_labels
,
old_assignees:
old_assignees
)
todo_service
.
mark_pending_todos_as_done
(
issue
,
current_user
)
todo_service
.
resolve_todos_for_target
(
issue
,
current_user
)
end
if
issue
.
previous_changes
.
include?
(
'title'
)
||
...
...
@@ -68,7 +68,7 @@ module Issues
end
def
handle_task_changes
(
issuable
)
todo_service
.
mark_pending_todos_as_done
(
issuable
,
current_user
)
todo_service
.
resolve_todos_for_target
(
issuable
,
current_user
)
todo_service
.
update_issue
(
issuable
,
current_user
)
end
...
...
app/services/merge_requests/update_service.rb
View file @
7ef44a97
...
...
@@ -27,7 +27,7 @@ module MergeRequests
old_assignees
=
old_associations
.
fetch
(
:assignees
,
[])
if
has_changes?
(
merge_request
,
old_labels:
old_labels
,
old_assignees:
old_assignees
)
todo_service
.
mark_pending_todos_as_done
(
merge_request
,
current_user
)
todo_service
.
resolve_todos_for_target
(
merge_request
,
current_user
)
end
if
merge_request
.
previous_changes
.
include?
(
'title'
)
||
...
...
@@ -73,7 +73,7 @@ module MergeRequests
end
def
handle_task_changes
(
merge_request
)
todo_service
.
mark_pending_todos_as_done
(
merge_request
,
current_user
)
todo_service
.
resolve_todos_for_target
(
merge_request
,
current_user
)
todo_service
.
update_merge_request
(
merge_request
,
current_user
)
end
...
...
app/services/todo_service.rb
View file @
7ef44a97
...
...
@@ -30,7 +30,7 @@ class TodoService
# * mark all pending todos related to the target for the current user as done
#
def
close_issue
(
issue
,
current_user
)
mark_pending_todos_as_done
(
issue
,
current_user
)
resolve_todos_for_target
(
issue
,
current_user
)
end
# When we destroy a todo target we should:
...
...
@@ -79,7 +79,7 @@ class TodoService
# * mark all pending todos related to the target for the current user as done
#
def
close_merge_request
(
merge_request
,
current_user
)
mark_pending_todos_as_done
(
merge_request
,
current_user
)
resolve_todos_for_target
(
merge_request
,
current_user
)
end
# When merge a merge request we should:
...
...
@@ -87,7 +87,7 @@ class TodoService
# * mark all pending todos related to the target for the current user as done
#
def
merge_merge_request
(
merge_request
,
current_user
)
mark_pending_todos_as_done
(
merge_request
,
current_user
)
resolve_todos_for_target
(
merge_request
,
current_user
)
end
# When a build fails on the HEAD of a merge request we should:
...
...
@@ -105,7 +105,7 @@ class TodoService
# * mark all pending todos related to the merge request for that user as done
#
def
merge_request_push
(
merge_request
,
current_user
)
mark_pending_todos_as_done
(
merge_request
,
current_user
)
resolve_todos_for_target
(
merge_request
,
current_user
)
end
# When a build is retried to a merge request we should:
...
...
@@ -114,7 +114,7 @@ class TodoService
#
def
merge_request_build_retried
(
merge_request
)
merge_request
.
merge_participants
.
each
do
|
user
|
mark_pending_todos_as_done
(
merge_request
,
user
)
resolve_todos_for_target
(
merge_request
,
user
)
end
end
...
...
@@ -151,76 +151,60 @@ class TodoService
# * mark all pending todos related to the awardable for the current user as done
#
def
new_award_emoji
(
awardable
,
current_user
)
mark_pending_todos_as_done
(
awardable
,
current_user
)
resolve_todos_for_target
(
awardable
,
current_user
)
end
# When marking pending todos as done we should:
#
# * mark all pending todos related to the target for the current user as done
#
def
mark_pending_todos_as_done
(
target
,
user
)
attributes
=
attributes_for_target
(
target
)
pending_todos
(
user
,
attributes
).
update_all
(
state: :done
)
user
.
update_todos_count_cache
# When user marks an issue as todo
def
mark_todo
(
issuable
,
current_user
)
attributes
=
attributes_for_todo
(
issuable
.
project
,
issuable
,
current_user
,
Todo
::
MARKED
)
create_todos
(
current_user
,
attributes
)
end
# When user marks some todos as done
def
mark_todos_as_done
(
todos
,
current_user
)
update_todos_state
(
todos
,
current_user
,
:done
)
def
todo_exist?
(
issuable
,
current_user
)
TodosFinder
.
new
(
current_user
).
any_for_target?
(
issuable
,
:pending
)
end
def
mark_todos_as_done_by_ids
(
ids
,
current_user
)
todos
=
todos_by_ids
(
ids
,
current_user
)
mark_todos_as_done
(
todos
,
current_user
)
end
# Resolves all todos related to target
def
resolve_todos_for_target
(
target
,
current_user
)
attributes
=
attributes_for_target
(
target
)
def
mark_all_todos_as_done_by_user
(
current_user
)
todos
=
TodosFinder
.
new
(
current_user
).
execute
mark_todos_as_done
(
todos
,
current_user
)
resolve_todos
(
pending_todos
(
current_user
,
attributes
),
current_user
)
end
def
mark_todo_as_done
(
todo
,
current_user
)
return
if
todo
.
done?
todo
.
update
(
state: :done
)
def
resolve_todos
(
todos
,
current_user
,
resolution: :done
,
resolved_by_action: :system_done
)
todos_ids
=
todos
.
batch_update
(
state:
resolution
,
resolved_by_action:
resolved_by_action
)
current_user
.
update_todos_count_cache
end
# When user marks some todos as pending
def
mark_todos_as_pending
(
todos
,
current_user
)
update_todos_state
(
todos
,
current_user
,
:pending
)
todos_ids
end
def
mark_todos_as_pending_by_ids
(
ids
,
current_user
)
todos
=
todos_by_ids
(
ids
,
current_user
)
mark_todos_as_pending
(
todos
,
current_user
)
end
def
resolve_todo
(
todo
,
current_user
,
resolution: :done
,
resolved_by_action: :system_done
)
return
if
todo
.
done?
# When user marks an issue as todo
def
mark_todo
(
issuable
,
current_user
)
attributes
=
attributes_for_todo
(
issuable
.
project
,
issuable
,
current_user
,
Todo
::
MARKED
)
create_todos
(
current_user
,
attributes
)
end
todo
.
update
(
state:
resolution
,
resolved_by_action:
resolved_by_action
)
def
todo_exist?
(
issuable
,
current_user
)
TodosFinder
.
new
(
current_user
).
any_for_target?
(
issuable
,
:pending
)
current_user
.
update_todos_count_cache
end
private
def
restore_todos
(
todos
,
current_user
)
todos_ids
=
todos
.
batch_update
(
state: :pending
)
def
todos_by_ids
(
ids
,
current_user
)
current_user
.
todos_limited_to
(
Array
(
ids
))
current_user
.
update_todos_count_cache
todos_ids
end
def
update_todos_state
(
todos
,
current_user
,
state
)
todos_ids
=
todos
.
update_state
(
state
)
def
restore_todo
(
todo
,
current_user
)
return
if
todo
.
pending?
current_user
.
update_todos_count_cache
todo
.
update
(
state: :pending
)
todos_ids
current_user
.
update_todos_count_cache
end
private
def
create_todos
(
users
,
attributes
)
Array
(
users
).
map
do
|
user
|
next
if
pending_todos
(
user
,
attributes
).
exists?
...
...
@@ -252,9 +236,9 @@ class TodoService
return
unless
note
.
can_create_todo?
project
=
note
.
project
target
=
note
.
noteable
target
=
note
.
noteable
mark_pending_todos_as_done
(
target
,
author
)
resolve_todos_for_target
(
target
,
author
)
create_mention_todos
(
project
,
target
,
author
,
note
,
skip_users
)
end
...
...
changelogs/unreleased/216045-capture-todo-resolution.yml
0 → 100644
View file @
7ef44a97
---
title
:
Store Todo resolution method
merge_request
:
32753
author
:
type
:
added
db/migrate/20200520103514_add_todo_resolved_by_action.rb
0 → 100644
View file @
7ef44a97
# frozen_string_literal: true
class
AddTodoResolvedByAction
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
up
with_lock_retries
do
add_column
:todos
,
:resolved_by_action
,
:integer
,
limit:
2
end
end
def
down
with_lock_retries
do
remove_column
:todos
,
:resolved_by_action
end
end
end
db/structure.sql
View file @
7ef44a97
...
...
@@ -6522,7 +6522,8 @@ CREATE TABLE public.todos (
updated_at
timestamp
without
time
zone
,
note_id
integer
,
commit_id
character
varying
,
group_id
integer
group_id
integer
,
resolved_by_action
smallint
);
CREATE
SEQUENCE
public
.
todos_id_seq
...
...
@@ -13959,6 +13960,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200519115908
20200519171058
20200519194042
20200520103514
20200525114553
20200525121014
20200526120714
...
...
ee/app/services/epics/update_service.rb
View file @
7ef44a97
...
...
@@ -31,14 +31,14 @@ module Epics
old_labels
=
old_associations
.
fetch
(
:labels
,
[])
if
has_changes?
(
epic
,
old_labels:
old_labels
)
todo_service
.
mark_pending_todos_as_done
(
epic
,
current_user
)
todo_service
.
resolve_todos_for_target
(
epic
,
current_user
)
end
todo_service
.
update_epic
(
epic
,
current_user
,
old_mentioned_users
)
end
def
handle_task_changes
(
epic
)
todo_service
.
mark_pending_todos_as_done
(
epic
,
current_user
)
todo_service
.
resolve_todos_for_target
(
epic
,
current_user
)
todo_service
.
update_epic
(
epic
,
current_user
)
end
...
...
ee/app/services/merge_requests/approval_service.rb
View file @
7ef44a97
...
...
@@ -44,7 +44,7 @@ module MergeRequests
end
def
mark_pending_todos_as_done
(
merge_request
)
todo_service
.
mark_pending_todos_as_done
(
merge_request
,
current_user
)
todo_service
.
resolve_todos_for_target
(
merge_request
,
current_user
)
end
def
calculate_approvals_metrics
(
merge_request
)
...
...
lib/api/todos.rb
View file @
7ef44a97
...
...
@@ -91,16 +91,18 @@ module API
requires
:id
,
type:
Integer
,
desc:
'The ID of the todo being marked as done'
end
post
':id/mark_as_done'
do
TodoService
.
new
.
mark_todos_as_done_by_ids
(
params
[
:id
],
current_user
)
todo
=
current_user
.
todos
.
find
(
params
[
:id
])
TodoService
.
new
.
resolve_todo
(
todo
,
current_user
,
resolved_by_action: :api_done
)
present
todo
,
with:
Entities
::
Todo
,
current_user:
current_user
end
desc
'Mark all todos as done'
post
'/mark_as_done'
do
todos
=
find_todos
TodoService
.
new
.
mark_todos_as_done
(
todos
,
current_user
)
TodoService
.
new
.
resolve_todos
(
todos
,
current_user
,
resolved_by_action: :api_all_done
)
no_content!
end
...
...
spec/features/dashboard/todos/todos_spec.rb
View file @
7ef44a97
...
...
@@ -114,7 +114,7 @@ describe 'Dashboard Todos' do
context
'todo is stale on the page'
do
before
do
todos
=
TodosFinder
.
new
(
user
,
state: :pending
).
execute
TodoService
.
new
.
mark_todos_as_done
(
todos
,
user
)
TodoService
.
new
.
resolve_todos
(
todos
,
user
)
end
it_behaves_like
'deleting the todo'
...
...
spec/models/todo_spec.rb
View file @
7ef44a97
...
...
@@ -393,10 +393,10 @@ describe Todo do
end
end
describe
'.
update_st
ate'
do
describe
'.
batch_upd
ate'
do
it
'updates the state of todos'
do
todo
=
create
(
:todo
,
:pending
)
ids
=
described_class
.
update_state
(
:done
)
ids
=
described_class
.
batch_update
(
state:
:done
)
todo
.
reload
...
...
@@ -407,7 +407,7 @@ describe Todo do
it
'does not update todos that already have the given state'
do
create
(
:todo
,
:pending
)
expect
(
described_class
.
update_state
(
:pending
)).
to
be_empty
expect
(
described_class
.
batch_update
(
state:
:pending
)).
to
be_empty
end
it
'updates updated_at'
do
...
...
@@ -416,7 +416,7 @@ describe Todo do
Timecop
.
freeze
(
1
.
day
.
from_now
)
do
expected_update_date
=
Time
.
current
.
utc
ids
=
described_class
.
update_state
(
:done
)
ids
=
described_class
.
batch_update
(
state:
:done
)
expect
(
Todo
.
where
(
id:
ids
).
map
(
&
:updated_at
)).
to
all
(
be_like_time
(
expected_update_date
))
end
...
...
spec/services/todo_service_spec.rb
View file @
7ef44a97
...
...
@@ -274,12 +274,12 @@ describe TodoService do
end
end
describe
'#
mark_pending_todos_as_done
'
do
describe
'#
resolve_todos_for_target
'
do
it
'marks related pending todos to the target for the user as done'
do
first_todo
=
create
(
:todo
,
:assigned
,
user:
john_doe
,
project:
project
,
target:
issue
,
author:
author
)
second_todo
=
create
(
:todo
,
:assigned
,
user:
john_doe
,
project:
project
,
target:
issue
,
author:
author
)
service
.
mark_pending_todos_as_done
(
issue
,
john_doe
)
service
.
resolve_todos_for_target
(
issue
,
john_doe
)
expect
(
first_todo
.
reload
).
to
be_done
expect
(
second_todo
.
reload
).
to
be_done
...
...
@@ -293,7 +293,7 @@ describe TodoService do
expect
(
john_doe
.
todos_pending_count
).
to
eq
(
1
)
expect
(
john_doe
).
to
receive
(
:update_todos_count_cache
).
and_call_original
service
.
mark_pending_todos_as_done
(
issue
,
john_doe
)
service
.
resolve_todos_for_target
(
issue
,
john_doe
)
expect
(
john_doe
.
todos_done_count
).
to
eq
(
1
)
expect
(
john_doe
.
todos_pending_count
).
to
eq
(
0
)
...
...
@@ -301,59 +301,6 @@ describe TodoService do
end
end
shared_examples
'updating todos state'
do
|
meth
,
state
,
new_state
|
let!
(
:first_todo
)
{
create
(
:todo
,
state
,
user:
john_doe
,
project:
project
,
target:
issue
,
author:
author
)
}
let!
(
:second_todo
)
{
create
(
:todo
,
state
,
user:
john_doe
,
project:
project
,
target:
issue
,
author:
author
)
}
it
'updates related todos for the user with the new_state'
do
service
.
send
(
meth
,
collection
,
john_doe
)
expect
(
first_todo
.
reload
.
state?
(
new_state
)).
to
be
true
expect
(
second_todo
.
reload
.
state?
(
new_state
)).
to
be
true
end
it
'returns the updated ids'
do
expect
(
service
.
send
(
meth
,
collection
,
john_doe
)).
to
match_array
([
first_todo
.
id
,
second_todo
.
id
])
end
describe
'cached counts'
do
it
'updates when todos change'
do
expect
(
john_doe
.
todos
.
where
(
state:
new_state
).
count
).
to
eq
(
0
)
expect
(
john_doe
.
todos
.
where
(
state:
state
).
count
).
to
eq
(
2
)
expect
(
john_doe
).
to
receive
(
:update_todos_count_cache
).
and_call_original
service
.
send
(
meth
,
collection
,
john_doe
)
expect
(
john_doe
.
todos
.
where
(
state:
new_state
).
count
).
to
eq
(
2
)
expect
(
john_doe
.
todos
.
where
(
state:
state
).
count
).
to
eq
(
0
)
end
end
end
describe
'#mark_todos_as_done'
do
it_behaves_like
'updating todos state'
,
:mark_todos_as_done
,
:pending
,
:done
do
let
(
:collection
)
{
Todo
.
all
}
end
end
describe
'#mark_todos_as_done_by_ids'
do
it_behaves_like
'updating todos state'
,
:mark_todos_as_done_by_ids
,
:pending
,
:done
do
let
(
:collection
)
{
[
first_todo
,
second_todo
].
map
(
&
:id
)
}
end
end
describe
'#mark_todos_as_pending'
do
it_behaves_like
'updating todos state'
,
:mark_todos_as_pending
,
:done
,
:pending
do
let
(
:collection
)
{
Todo
.
all
}
end
end
describe
'#mark_todos_as_pending_by_ids'
do
it_behaves_like
'updating todos state'
,
:mark_todos_as_pending_by_ids
,
:done
,
:pending
do
let
(
:collection
)
{
[
first_todo
,
second_todo
].
map
(
&
:id
)
}
end
end
describe
'#new_note'
do
let!
(
:first_todo
)
{
create
(
:todo
,
:assigned
,
user:
john_doe
,
project:
project
,
target:
issue
,
author:
author
)
}
let!
(
:second_todo
)
{
create
(
:todo
,
:assigned
,
user:
john_doe
,
project:
project
,
target:
issue
,
author:
author
)
}
...
...
@@ -1000,121 +947,111 @@ describe TodoService do
expect
(
john_doe
.
todos_pending_count
).
to
eq
(
1
)
end
describe
'#mark_todos_as_done'
do
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
author:
author
,
assignees:
[
john_doe
])
}
let
(
:another_issue
)
{
create
(
:issue
,
project:
project
,
author:
author
,
assignees:
[
john_doe
])
}
shared_examples
'updating todos state'
do
|
state
,
new_state
,
new_resolved_by
=
nil
|
let!
(
:first_todo
)
{
create
(
:todo
,
state
,
user:
john_doe
)
}
let!
(
:second_todo
)
{
create
(
:todo
,
state
,
user:
john_doe
)
}
let
(
:collection
)
{
Todo
.
all
}
it
'
marks a relation of todos as don
e'
do
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
it
'
updates related todos for the user with the new_stat
e'
do
method_call
todos
=
TodosFinder
.
new
(
john_doe
,
{}).
execute
expect
{
described_class
.
new
.
mark_todos_as_done
(
todos
,
john_doe
)
}
.
to
change
{
john_doe
.
todos
.
done
.
count
}.
from
(
0
).
to
(
1
)
expect
(
collection
.
all?
{
|
todo
|
todo
.
reload
.
state?
(
new_state
)}).
to
be_truthy
end
it
'marks an array of todos as done'
do
todo
=
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
if
new_resolved_by
it
'updates resolution mechanism'
do
method_call
todos
=
TodosFinder
.
new
(
john_doe
,
{}).
execute
expect
{
described_class
.
new
.
mark_todos_as_done
(
todos
,
john_doe
)
}
.
to
change
{
todo
.
reload
.
state
}.
from
(
'pending'
).
to
(
'done'
)
expect
(
collection
.
all?
{
|
todo
|
todo
.
reload
.
resolved_by_action
==
new_resolved_by
}).
to
be_truthy
end
end
it
'returns the ids of updated todos'
do
# Needed on API
todo
=
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
todos
=
TodosFinder
.
new
(
john_doe
,
{}).
execute
expect
(
described_class
.
new
.
mark_todos_as_done
(
todos
,
john_doe
)).
to
eq
([
todo
.
id
])
it
'returns the updated ids'
do
expect
(
method_call
).
to
match_array
([
first_todo
.
id
,
second_todo
.
id
])
end
context
'when some of the todos are done already'
do
let!
(
:first_todo
)
{
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
}
let!
(
:second_todo
)
{
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
another_issue
,
project:
project
)
}
describe
'cached counts'
do
it
'updates when todos change'
do
expect
(
john_doe
.
todos
.
where
(
state:
new_state
).
count
).
to
eq
(
0
)
expect
(
john_doe
.
todos
.
where
(
state:
state
).
count
).
to
eq
(
2
)
expect
(
john_doe
).
to
receive
(
:update_todos_count_cache
).
and_call_original
it
'returns the ids of those still pending'
do
described_class
.
new
.
mark_pending_todos_as_done
(
issue
,
john_doe
)
method_call
expect
(
described_class
.
new
.
mark_todos_as_done
(
Todo
.
all
,
john_doe
)).
to
eq
([
second_todo
.
id
])
end
it
'returns an empty array if all are done'
do
described_class
.
new
.
mark_pending_todos_as_done
(
issue
,
john_doe
)
described_class
.
new
.
mark_pending_todos_as_done
(
another_issue
,
john_doe
)
expect
(
described_class
.
new
.
mark_todos_as_done
(
Todo
.
all
,
john_doe
)).
to
eq
([])
expect
(
john_doe
.
todos
.
where
(
state:
new_state
).
count
).
to
eq
(
2
)
expect
(
john_doe
.
todos
.
where
(
state:
state
).
count
).
to
eq
(
0
)
end
end
end
describe
'#mark_todo_as_done'
do
it
'marks a todo done'
do
todo1
=
create
(
:todo
,
:pending
,
user:
john_doe
)
described_class
.
new
.
mark_todo_as_done
(
todo1
,
john_doe
)
expect
(
todo1
.
reload
.
state
).
to
eq
(
'done'
)
end
context
'when todo is already in state done'
do
let
(
:todo1
)
{
create
(
:todo
,
:done
,
user:
john_doe
)
}
it
'does not update the todo'
do
expect
{
described_class
.
new
.
mark_todo_as_done
(
todo1
,
john_doe
)
}.
not_to
change
(
todo1
.
reload
,
:state
)
describe
'#resolve_todos'
do
it_behaves_like
'updating todos state'
,
:pending
,
:done
,
'mark_done'
do
subject
(
:method_call
)
do
service
.
resolve_todos
(
collection
,
john_doe
,
resolution: :done
,
resolved_by_action: :mark_done
)
end
end
end
it
'does not update cache count
'
do
expect
(
john_doe
).
not_to
receive
(
:update_todos_count_cache
)
described_class
.
new
.
mark_todo_as_done
(
todo1
,
john_doe
)
describe
'#restore_todos
'
do
it_behaves_like
'updating todos state'
,
:done
,
:pending
do
subject
(
:method_call
)
do
service
.
restore_todos
(
collection
,
john_doe
)
end
end
end
describe
'#mark_all_todos_as_done_by_user'
do
it
'marks all todos done'
do
todo1
=
create
(
:todo
,
user:
john_doe
,
state: :pending
)
todo2
=
create
(
:todo
,
user:
john_doe
,
state: :done
)
todo3
=
create
(
:todo
,
user:
john_doe
,
state: :pending
)
describe
'#resolve_todo'
do
let!
(
:todo
)
{
create
(
:todo
,
:assigned
,
user:
john_doe
)
}
ids
=
described_class
.
new
.
mark_all_todos_as_done_by_user
(
john_doe
)
it
'marks pending todo as done'
do
expect
do
service
.
resolve_todo
(
todo
,
john_doe
)
todo
.
reload
end
.
to
change
{
todo
.
done?
}.
to
(
true
)
end
expect
(
ids
).
to
contain_exactly
(
todo1
.
id
,
todo3
.
id
)
expect
(
todo1
.
reload
.
state
).
to
eq
(
'done'
)
expect
(
todo2
.
reload
.
state
).
to
eq
(
'done'
)
expect
(
todo3
.
reload
.
state
).
to
eq
(
'done'
)
it
'saves resolution mechanism'
do
expect
do
service
.
resolve_todo
(
todo
,
john_doe
,
resolved_by_action: :mark_done
)
todo
.
reload
end
.
to
change
{
todo
.
resolved_by_mark_done?
}.
to
(
true
)
end
end
describe
'#mark_todos_as_done_by_ids'
do
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
author:
author
,
assignees:
[
john_doe
])
}
let
(
:another_issue
)
{
create
(
:issue
,
project:
project
,
author:
author
,
assignees:
[
john_doe
])
}
context
'cached counts'
do
it
'updates when todos change'
do
expect
(
john_doe
.
todos_done_count
).
to
eq
(
0
)
expect
(
john_doe
.
todos_pending_count
).
to
eq
(
1
)
expect
(
john_doe
).
to
receive
(
:update_todos_count_cache
).
and_call_original
it
'marks an array of todo ids as done'
do
todo
=
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
another_todo
=
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
another_issue
,
project:
project
)
service
.
resolve_todo
(
todo
,
john_doe
)
expect
{
described_class
.
new
.
mark_todos_as_done_by_ids
([
todo
.
id
,
another_todo
.
id
],
john_doe
)
}
.
to
change
{
john_doe
.
todos
.
done
.
count
}.
from
(
0
).
to
(
2
)
expect
(
john_doe
.
todos_done_count
).
to
eq
(
1
)
expect
(
john_doe
.
todos_pending_count
).
to
eq
(
0
)
end
end
end
it
'marks a single todo id as done
'
do
todo
=
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
describe
'#restore_todo
'
do
let!
(
:todo
)
{
create
(
:todo
,
:done
,
user:
john_doe
)
}
expect
{
described_class
.
new
.
mark_todos_as_done_by_ids
(
todo
.
id
,
john_doe
)
}
.
to
change
{
todo
.
reload
.
state
}.
from
(
'pending'
).
to
(
'done'
)
it
'marks resolved todo as pending'
do
expect
do
service
.
restore_todo
(
todo
,
john_doe
)
todo
.
reload
end
.
to
change
{
todo
.
pending?
}.
to
(
true
)
end
it
'caches the number of todos of a user'
,
:use_clean_rails_memory_store_caching
do
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
todo
=
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
context
'cached counts'
do
it
'updates when todos change'
do
expect
(
john_doe
.
todos_done_count
).
to
eq
(
1
)
expect
(
john_doe
.
todos_pending_count
).
to
eq
(
0
)
expect
(
john_doe
).
to
receive
(
:update_todos_count_cache
).
and_call_original
described_class
.
new
.
mark_todos_as_done_by_ids
(
todo
,
john_doe
)
service
.
restore_todo
(
todo
,
john_doe
)
# Make sure no TodosFinder is inialized to perform counting
expect
(
TodosFinder
).
not_to
receive
(
:new
)
expect
(
john_doe
.
todos_done_count
).
to
eq
(
1
)
expect
(
john_doe
.
todos_pending_count
).
to
eq
(
1
)
expect
(
john_doe
.
todos_done_count
).
to
eq
(
0
)
expect
(
john_doe
.
todos_pending_count
).
to
eq
(
1
)
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