summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/services/slash_commands/interpret_service.rb4
-rw-r--r--app/services/todo_service.rb4
-rw-r--r--spec/lib/gitlab/slash_commands/dsl_spec.rb2
-rw-r--r--spec/services/todo_service_spec.rb12
4 files changed, 19 insertions, 3 deletions
diff --git a/app/services/slash_commands/interpret_service.rb b/app/services/slash_commands/interpret_service.rb
index ae22ed6b845..f8aeefbfbce 100644
--- a/app/services/slash_commands/interpret_service.rb
+++ b/app/services/slash_commands/interpret_service.rb
@@ -140,7 +140,7 @@ module SlashCommands
condition do
noteable.persisted? &&
current_user &&
- !TodosFinder.new(current_user).execute.exists?(target: noteable)
+ !TodoService.new.todo_exist?(noteable, current_user)
end
command :todo do
@updates[:todo_event] = 'add'
@@ -149,7 +149,7 @@ module SlashCommands
desc 'Mark todo as done'
condition do
current_user &&
- TodosFinder.new(current_user).execute.exists?(target: noteable)
+ TodoService.new.todo_exist?(noteable, current_user)
end
command :done do
@updates[:todo_event] = 'done'
diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb
index 6b48d68cccb..db1578d1dc4 100644
--- a/app/services/todo_service.rb
+++ b/app/services/todo_service.rb
@@ -154,6 +154,10 @@ class TodoService
create_todos(current_user, attributes)
end
+ def todo_exist?(issuable, current_user)
+ TodosFinder.new(current_user).execute.exists?(target: issuable)
+ end
+
private
def create_todos(users, attributes)
diff --git a/spec/lib/gitlab/slash_commands/dsl_spec.rb b/spec/lib/gitlab/slash_commands/dsl_spec.rb
index 7c946313ae1..385f534ad6f 100644
--- a/spec/lib/gitlab/slash_commands/dsl_spec.rb
+++ b/spec/lib/gitlab/slash_commands/dsl_spec.rb
@@ -51,7 +51,7 @@ describe Gitlab::SlashCommands::Dsl do
{ name: :one_arg, aliases: [:once, :first], description: '', params: ['The first argument'], noop: false, cond_block: nil },
{ name: :two_args, aliases: [], description: '', params: ['The first argument', 'The second argument'], noop: false, cond_block: nil },
{ name: :cc, aliases: [], description: '', params: [], noop: true, cond_block: nil },
- { name: :wildcard, aliases: [], description: '', params: [], noop: false, cond_block: nil}
+ { name: :wildcard, aliases: [], description: '', params: [], noop: false, cond_block: nil }
]
end
diff --git a/spec/services/todo_service_spec.rb b/spec/services/todo_service_spec.rb
index 34d8ea9090e..4c41df0d4f5 100644
--- a/spec/services/todo_service_spec.rb
+++ b/spec/services/todo_service_spec.rb
@@ -290,6 +290,18 @@ describe TodoService, services: true do
should_create_todo(user: author, target: unassigned_issue, action: Todo::MARKED)
end
end
+
+ describe '#todo_exists?' do
+ it 'returns false when no todo exist for the given issuable' do
+ expect(service.todo_exist?(unassigned_issue, author)).to be_falsy
+ end
+
+ it 'returns true when a todo exist for the given issuable' do
+ service.mark_todo(unassigned_issue, author)
+
+ expect(service.todo_exist?(unassigned_issue, author)).to be_truthy
+ end
+ end
end
describe 'Merge Requests' do