Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2019-01-30 03:31:31 +0300
committerBrett Walker <bwalker@gitlab.com>2019-02-07 18:28:35 +0300
commit79bd1b8717599205fd1bf4f79048d3065b500536 (patch)
tree5c69bd43f58997d97504cc2063c6064f434ba11f /spec
parentca154f0ff4f15d717a0fcf7a3cb75921ba6880ee (diff)
Enable fast task lists for merge requests
Allow single tasks to be updated quickly
Diffstat (limited to 'spec')
-rw-r--r--spec/services/issues/update_service_spec.rb72
-rw-r--r--spec/services/merge_requests/update_service_spec.rb2
-rw-r--r--spec/services/task_list_toggle_service_spec.rb11
-rw-r--r--spec/support/shared_examples/issuable_shared_examples.rb73
4 files changed, 88 insertions, 70 deletions
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb
index ef76e2311b1..931e47d3a77 100644
--- a/spec/services/issues/update_service_spec.rb
+++ b/spec/services/issues/update_service_spec.rb
@@ -471,6 +471,8 @@ describe Issues::UpdateService, :mailer do
it { expect(issue.tasks?).to eq(true) }
+ it_behaves_like 'updating a single task'
+
context 'when tasks are marked as completed' do
before do
update_issue(description: "- [x] Task 1\n- [X] Task 2")
@@ -543,76 +545,6 @@ 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 }
diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb
index be5ad849ba7..20580bf14b9 100644
--- a/spec/services/merge_requests/update_service_spec.rb
+++ b/spec/services/merge_requests/update_service_spec.rb
@@ -466,6 +466,8 @@ describe MergeRequests::UpdateService, :mailer do
it { expect(@merge_request.tasks?).to eq(true) }
+ it_behaves_like 'updating a single task'
+
context 'when tasks are marked as completed' do
before do
update_merge_request({ description: "- [x] Task 1\n- [X] Task 2" })
diff --git a/spec/services/task_list_toggle_service_spec.rb b/spec/services/task_list_toggle_service_spec.rb
index cc64dd25085..7c5480d382f 100644
--- a/spec/services/task_list_toggle_service_spec.rb
+++ b/spec/services/task_list_toggle_service_spec.rb
@@ -67,6 +67,17 @@ describe TaskListToggleService do
expect(toggler.execute).to be_falsey
end
+ it 'tolerates \r\n line endings' do
+ rn_markdown = markdown.gsub("\n", "\r\n")
+ toggler = described_class.new(rn_markdown, markdown_html,
+ toggle_as_checked: true,
+ line_source: '* [ ] Task 1', line_number: 1)
+
+ expect(toggler.execute).to be_truthy
+ expect(toggler.updated_markdown.lines[0]).to eq "* [x] Task 1\r\n"
+ expect(toggler.updated_markdown_html).to include('disabled checked> Task 1')
+ end
+
it 'returns false if markdown is nil' do
toggler = described_class.new(nil, markdown_html,
toggle_as_checked: false,
diff --git a/spec/support/shared_examples/issuable_shared_examples.rb b/spec/support/shared_examples/issuable_shared_examples.rb
index 42f3b4db23c..c3d40c5b231 100644
--- a/spec/support/shared_examples/issuable_shared_examples.rb
+++ b/spec/support/shared_examples/issuable_shared_examples.rb
@@ -36,3 +36,76 @@ shared_examples 'system notes for milestones' do
end
end
end
+
+shared_examples 'updating a single task' do
+ def update_issuable(opts)
+ issuable = try(:issue) || try(:merge_request)
+ described_class.new(project, user, opts).execute(issuable)
+ end
+
+ before do
+ update_issuable(description: "- [ ] Task 1\n- [ ] Task 2")
+ end
+
+ 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