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
39fc0db3
Commit
39fc0db3
authored
Sep 17, 2019
by
Marc Schwede
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added optional for Todo state
cf.
https://gitlab.com/gitlab-org/gitlab/merge_requests/16837#note_217807588
parent
7a31cfe9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
9 deletions
+11
-9
app/finders/todos_finder.rb
app/finders/todos_finder.rb
+4
-3
app/models/todo.rb
app/models/todo.rb
+4
-3
app/services/todo_service.rb
app/services/todo_service.rb
+1
-1
spec/models/todo_spec.rb
spec/models/todo_spec.rb
+2
-2
No files found.
app/finders/todos_finder.rb
View file @
39fc0db3
...
...
@@ -47,11 +47,12 @@ class TodosFinder
sort
(
items
)
end
# Returns `true` if the current user has any todos for the given target.
# Returns `true` if the current user has any todos for the given target
with the optional given state
.
#
# target - The value of the `target_type` column, such as `Issue`.
def
any_for_target?
(
target
)
current_user
.
todos
.
any_for_target?
(
target
)
# state - The value of the `state` column, such as `pending` or `done`.
def
any_for_target?
(
target
,
*
state
)
current_user
.
todos
.
any_for_target?
(
target
,
state
)
end
private
...
...
app/models/todo.rb
View file @
39fc0db3
...
...
@@ -89,11 +89,12 @@ class Todo < ApplicationRecord
])
end
# Returns `true` if the current user has any todos for the given target.
# Returns `true` if the current user has any todos for the given target
with the optional given state
.
#
# target - The value of the `target_type` column, such as `Issue`.
def
any_for_target?
(
target
)
exists?
(
target:
target
,
state: :pending
)
# state - The value of the `state` column, such as `pending` or `done`.
def
any_for_target?
(
target
,
*
state
)
state
.
empty?
?
exists?
(
target:
target
)
:
exists?
(
target:
target
,
state:
state
)
end
# Updates the state of a relation of todos to the new state.
...
...
app/services/todo_service.rb
View file @
39fc0db3
...
...
@@ -191,7 +191,7 @@ class TodoService
end
def
todo_exist?
(
issuable
,
current_user
)
TodosFinder
.
new
(
current_user
).
any_for_target?
(
issuable
)
TodosFinder
.
new
(
current_user
).
any_for_target?
(
issuable
,
:pending
)
end
private
...
...
spec/models/todo_spec.rb
View file @
39fc0db3
...
...
@@ -281,12 +281,12 @@ describe Todo do
expect
(
described_class
.
any_for_target?
(
issue
)).
to
eq
(
true
)
end
it
'returns false if there are only todos for a given target with state done'
do
it
'returns false if there are only todos for a given target with state done
while searching for pending
'
do
issue
=
create
(
:issue
)
create
(
:todo
,
state: :done
,
target:
issue
)
create
(
:todo
,
state: :done
,
target:
issue
)
expect
(
described_class
.
any_for_target?
(
issue
)).
to
eq
(
false
)
expect
(
described_class
.
any_for_target?
(
issue
,
:pending
)).
to
eq
(
false
)
end
it
'returns false if there are no todos for a given target'
do
...
...
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