Commit 7a31cfe9 authored by Marc Schwede's avatar Marc Schwede

Refactored todo model to check only for pending todos

* extended todo_spec to fit adjustment to .any_target?
* with changelog
parent e3c8b6a1
...@@ -93,7 +93,7 @@ class Todo < ApplicationRecord ...@@ -93,7 +93,7 @@ class Todo < ApplicationRecord
# #
# target - The value of the `target_type` column, such as `Issue`. # target - The value of the `target_type` column, such as `Issue`.
def any_for_target?(target) def any_for_target?(target)
exists?(target: target) exists?(target: target, state: :pending)
end end
# Updates the state of a relation of todos to the new state. # Updates the state of a relation of todos to the new state.
......
---
title: Changed todo/done quick actions to work not only for first usage
merge_request:
author: Marc Schwede
type: fixed
...@@ -273,6 +273,22 @@ describe Todo do ...@@ -273,6 +273,22 @@ describe Todo do
expect(described_class.any_for_target?(todo.target)).to eq(true) expect(described_class.any_for_target?(todo.target)).to eq(true)
end end
it 'returns true if there is at least one todo for a given target with state pending' do
issue = create(:issue)
create(:todo, state: :done, target: issue)
create(:todo, state: :pending, target: issue)
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
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)
end
it 'returns false if there are no todos for a given target' do it 'returns false if there are no todos for a given target' do
issue = create(:issue) issue = create(:issue)
......
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