2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'cache counters invalidator' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'invalidates counter cache for assignees' do
|
|
|
|
expect_any_instance_of(User).to receive(:invalidate_merge_request_cache_counts)
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
described_class.new(project: project, current_user: user).execute(merge_request)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'updating a single task' do
|
2019-03-02 22:35:43 +05:30
|
|
|
def update_issuable(opts)
|
|
|
|
issuable = try(:issue) || try(:merge_request)
|
2021-06-08 01:23:25 +05:30
|
|
|
described_class.new(project: project, current_user: user, params: opts).execute(issuable)
|
2019-03-02 22:35:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
update_issuable(description: "- [ ] Task 1\n- [ ] Task 2")
|
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
context 'usage counters' do
|
|
|
|
it 'update as expected' do
|
|
|
|
if try(:merge_request)
|
|
|
|
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
|
|
|
|
.to receive(:track_task_item_status_changed).once.with(user: user)
|
|
|
|
else
|
|
|
|
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
|
|
|
|
.not_to receive(:track_task_item_status_changed)
|
|
|
|
end
|
|
|
|
|
|
|
|
update_issuable(
|
|
|
|
update_task: {
|
|
|
|
index: 1,
|
|
|
|
checked: true,
|
|
|
|
line_source: '- [ ] Task 1',
|
|
|
|
line_number: 1
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
context 'when a task is marked as completed' do
|
|
|
|
before do
|
|
|
|
update_issuable(update_task: { index: 1, checked: true, line_source: '- [ ] Task 1', line_number: 1 })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates system note about task status change' do
|
|
|
|
note1 = find_note('marked the task **Task 1** as completed')
|
|
|
|
|
|
|
|
expect(note1).not_to be_nil
|
|
|
|
|
|
|
|
description_notes = find_notes('description')
|
|
|
|
expect(description_notes.length).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a task is marked as incomplete' do
|
|
|
|
before do
|
|
|
|
update_issuable(description: "- [x] Task 1\n- [X] Task 2")
|
|
|
|
update_issuable(update_task: { index: 2, checked: false, line_source: '- [X] Task 2', line_number: 2 })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates system note about task status change' do
|
|
|
|
note1 = find_note('marked the task **Task 2** as incomplete')
|
|
|
|
|
|
|
|
expect(note1).not_to be_nil
|
|
|
|
|
|
|
|
description_notes = find_notes('description')
|
|
|
|
expect(description_notes.length).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the task position has been modified' do
|
|
|
|
before do
|
|
|
|
update_issuable(description: "- [ ] Task 1\n- [ ] Task 3\n- [ ] Task 2")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an exception' do
|
|
|
|
expect(Note.count).to eq(2)
|
|
|
|
expect do
|
|
|
|
update_issuable(update_task: { index: 2, checked: true, line_source: '- [ ] Task 2', line_number: 2 })
|
|
|
|
end.to raise_error(ActiveRecord::StaleObjectError)
|
|
|
|
expect(Note.count).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the content changes but not task line number' do
|
|
|
|
before do
|
|
|
|
update_issuable(description: "Paragraph\n\n- [ ] Task 1\n- [x] Task 2")
|
|
|
|
update_issuable(description: "Paragraph with more words\n\n- [ ] Task 1\n- [x] Task 2")
|
|
|
|
update_issuable(update_task: { index: 2, checked: false, line_source: '- [x] Task 2', line_number: 4 })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates system note about task status change' do
|
|
|
|
note1 = find_note('marked the task **Task 2** as incomplete')
|
|
|
|
|
|
|
|
expect(note1).not_to be_nil
|
|
|
|
|
|
|
|
description_notes = find_notes('description')
|
|
|
|
expect(description_notes.length).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|