From 816fad3530d3d9774733c4fa215d43b9b06a1f95 Mon Sep 17 00:00:00 2001 From: Jarka Kadlecova Date: Wed, 25 Jan 2017 08:24:14 +0100 Subject: =?UTF-8?q?Don=E2=80=99t=20count=20tasks=20that=20are=20not=20defi?= =?UTF-8?q?ned=20as=20list=20items=20correctly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/taskable.rb | 8 ++++---- changelogs/unreleased/26068_tasklist_issue.yml | 4 ++++ spec/support/taskable_shared_examples.rb | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 changelogs/unreleased/26068_tasklist_issue.yml diff --git a/app/models/concerns/taskable.rb b/app/models/concerns/taskable.rb index 68385dc47eb..25e2d8ea24e 100644 --- a/app/models/concerns/taskable.rb +++ b/app/models/concerns/taskable.rb @@ -11,10 +11,10 @@ module Taskable INCOMPLETE = 'incomplete'.freeze ITEM_PATTERN = / ^ - \s*(?:[-+*]|(?:\d+\.))? # optional list prefix - \s* # optional whitespace prefix - (\[\s\]|\[[xX]\]) # checkbox - (\s.+) # followed by whitespace and some text. + \s*(?:[-+*]|(?:\d+\.)) # list prefix required - task item has to be always in a list + \s+ # whitespace prefix has to be always presented for a list item + (\[\s\]|\[[xX]\]) # checkbox + (\s.+) # followed by whitespace and some text. /x def self.get_tasks(content) diff --git a/changelogs/unreleased/26068_tasklist_issue.yml b/changelogs/unreleased/26068_tasklist_issue.yml new file mode 100644 index 00000000000..c938351b8a7 --- /dev/null +++ b/changelogs/unreleased/26068_tasklist_issue.yml @@ -0,0 +1,4 @@ +--- +title: Don’t count tasks that are not defined as list items correctly +merge_request: 8526 +author: diff --git a/spec/support/taskable_shared_examples.rb b/spec/support/taskable_shared_examples.rb index 1b6c33248c9..4056ff06b84 100644 --- a/spec/support/taskable_shared_examples.rb +++ b/spec/support/taskable_shared_examples.rb @@ -72,6 +72,25 @@ shared_examples 'a Taskable' do end end + describe 'with tasks that are not formatted correctly' do + before do + subject.description = <<-EOT.strip_heredoc + [ ] task 1 + [ ] task 2 + + - [ ]task 1 + -[ ] task 2 + EOT + end + + it 'returns the correct task status' do + expect(subject.task_status).to match('0 of') + expect(subject.task_status).to match('0 tasks completed') + expect(subject.task_status_short).to match('0/') + expect(subject.task_status_short).to match('0 task') + end + end + describe 'with a complete task' do before do subject.description = <<-EOT.strip_heredoc -- cgit v1.2.1