Skip to content
Snippets Groups Projects
Verified Commit f29f9a1c authored by Alexandru Croitor's avatar Alexandru Croitor :three:
Browse files

Retain checklist item when deleting task

When a task is removed, we should retain the bullet item
in the description.

Changelog: fixed
parent 69daa0be
No related branches found
No related tags found
1 merge request!92478Retain checklist item when deleting task
......@@ -11,6 +11,7 @@ def initialize(work_item:, task:, line_number_start:, line_number_end:, lock_ver
@line_number_end = line_number_end
@lock_version = lock_version
@current_user = current_user
@task_reference = /#{Regexp.escape(@task.to_reference)}(?!\d)\+/
end
def execute
......@@ -26,7 +27,9 @@ def execute
line_matches_reference = (@line_number_start..@line_number_end).any? do |line_number|
markdown_line = source_lines[line_number - 1]
/#{Regexp.escape(@task.to_reference)}(?!\d)/.match?(markdown_line)
if @task_reference.match?(markdown_line)
markdown_line.sub!(@task_reference, @task.title)
end
end
unless line_matches_reference
......@@ -35,8 +38,6 @@ def execute
)
end
remove_task_lines!(source_lines)
::WorkItems::UpdateService.new(
project: @work_item.project,
current_user: @current_user,
......@@ -51,13 +52,5 @@ def execute
rescue ActiveRecord::StaleObjectError
::ServiceResponse.error(message: STALE_OBJECT_MESSAGE)
end
private
def remove_task_lines!(source_lines)
source_lines.delete_if.each_with_index do |_line, index|
index >= @line_number_start - 1 && index < @line_number_end
end
end
end
end
......@@ -54,7 +54,7 @@
end.to change(WorkItem, :count).by(-1).and(
change(IssueLink, :count).by(-1)
).and(
change(work_item, :description).from("- [ ] #{task.to_reference}+").to('')
change(work_item, :description).from("- [ ] #{task.to_reference}+").to("- [ ] #{task.title}")
)
expect(response).to have_gitlab_http_status(:success)
......
......@@ -67,7 +67,7 @@
it 'removes the task list item with the work item reference' do
expect do
service_result
end.to change(list_work_item, :description).from(list_work_item.description).to('')
end.to change(list_work_item, :description).from(list_work_item.description).to("- [ ] #{task.title}")
end
end
......
......@@ -82,7 +82,7 @@
let(:line_number_end) { 1 }
let(:work_item) { single_line_work_item }
it_behaves_like 'successful work item task reference removal service', ''
it_behaves_like 'successful work item task reference removal service', '- [ ] My title 1 single line'
context 'when description does not contain a task' do
let_it_be(:no_matching_work_item) { create(:work_item, project: project, description: 'no matching task') }
......@@ -102,7 +102,8 @@
end
context 'when task mardown spans multiple lines' do
it_behaves_like 'successful work item task reference removal service', "Any text\n\n* [x] task\n\nMore text"
it_behaves_like 'successful work item task reference removal service',
"Any text\n\n* [ ] Item to be converted\n My title 1 second line\n third line\n* [x] task\n\nMore text"
end
context 'when updating the work item fails' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment