Commit 39fc0db3 authored by Marc Schwede's avatar Marc Schwede
parent 7a31cfe9
......@@ -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
......
......@@ -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.
......
......@@ -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
......
......@@ -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
......
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