diff options
author | Brett Walker <bwalker@gitlab.com> | 2019-01-25 21:50:21 +0300 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2019-01-31 01:18:19 +0300 |
commit | dfeb412d9f09053a601075b04cca674787c6c275 (patch) | |
tree | efb0755ff670da6deebaf5d16db69eeebdfec1eb /spec/services/issues | |
parent | 2dc304855b7c58fda1773be9774b5d916aa0fe73 (diff) |
Specs for Issue::UpdateService
Diffstat (limited to 'spec/services/issues')
-rw-r--r-- | spec/services/issues/update_service_spec.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index ce20bf2bef6..26dc0919715 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -543,6 +543,76 @@ describe Issues::UpdateService, :mailer do end end + context 'when updating a single task' do + before do + update_issue(description: "- [ ] Task 1\n- [ ] Task 2") + end + + it { expect(issue.tasks?).to eq(true) } + + context 'when a task is marked as completed' do + before do + update_issue(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_issue(description: "- [x] Task 1\n- [X] Task 2") + update_issue(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_issue(description: "- [ ] Task 1\n- [ ] Task 3\n- [ ] Task 2") + end + + it 'raises an exception' do + expect(Note.count).to eq(2) + expect do + update_issue(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_issue(description: "Paragraph\n\n- [ ] Task 1\n- [x] Task 2") + update_issue(description: "Paragraph with more words\n\n- [ ] Task 1\n- [x] Task 2") + update_issue(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 + context 'updating labels' do let(:label3) { create(:label, project: project) } let(:result) { described_class.new(project, user, params).execute(issue).reload } |