diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-02-16 00:26:33 -0200 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-02-20 12:10:26 -0200 |
commit | e81061a211fedf9adaca8b053b6633988fdd5644 (patch) | |
tree | 4855440c7b31169eb2fc53ee8f80083cf21c8e26 /spec | |
parent | 48ddf9a407e0f98949301de7a2cbd7d62f8a4e47 (diff) | |
download | gitlab-ce-e81061a211fedf9adaca8b053b6633988fdd5644.tar.gz |
Marks pending tasks for an user as done when he edit an issue
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/tasks.rb | 10 | ||||
-rw-r--r-- | spec/services/issues/update_service_spec.rb | 77 | ||||
-rw-r--r-- | spec/services/task_service_spec.rb | 17 |
3 files changed, 93 insertions, 11 deletions
diff --git a/spec/factories/tasks.rb b/spec/factories/tasks.rb index cd04405774a..710b8324f1f 100644 --- a/spec/factories/tasks.rb +++ b/spec/factories/tasks.rb @@ -19,5 +19,15 @@ FactoryGirl.define do project author user + + factory :pending_assigned_task, traits: [:assgined, :pending] + + trait :assgined do + action { Task::ASSIGNED } + end + + trait :pending do + state { :pending } + end end end diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index 8f654517bce..1b7d5b45168 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -78,18 +78,74 @@ describe Issues::UpdateService, services: true do expect(note).not_to be_nil expect(note.note).to eq 'Title changed from **Old title** to **New title**' end + end - it 'creates a pending task if being reassigned' do - attributes = { - project: project, - author: user, - user: user2, - target: issue, - action: Task::ASSIGNED, - state: :pending - } + context 'task queue' do + let!(:pending_task) do + create(:pending_assigned_task, user: user, project: project, target: issue, author: user2) + end + + context 'when the title change' do + before do + update_issue({ title: 'New title' }) + end + + it 'marks pending tasks as done' do + expect(pending_task.reload.done?).to eq true + end + end + + context 'when the description change' do + before do + update_issue({ description: 'Also please fix' }) + end + + it 'marks pending tasks as done' do + expect(pending_task.reload.done?).to eq true + end + end + + context 'when is reassigned' do + before do + update_issue({ assignee: user2 }) + end + + it 'marks previous assignee pending tasks as done' do + expect(pending_task.reload.done?).to eq true + end - expect(Task.where(attributes).count).to eq 1 + it 'creates a pending task for new assignee' do + attributes = { + project: project, + author: user, + user: user2, + target: issue, + action: Task::ASSIGNED, + state: :pending + } + + expect(Task.where(attributes).count).to eq 1 + end + end + + context 'when the milestone change' do + before do + update_issue({ milestone: create(:milestone) }) + end + + it 'marks pending tasks as done' do + expect(pending_task.reload.done?).to eq true + end + end + + context 'when the labels change' do + before do + update_issue({ label_ids: [label.id] }) + end + + it 'marks pending tasks as done' do + expect(pending_task.reload.done?).to eq true + end end end @@ -157,6 +213,5 @@ describe Issues::UpdateService, services: true do end end end - end end diff --git a/spec/services/task_service_spec.rb b/spec/services/task_service_spec.rb index db9f77fd12d..e8920c59fee 100644 --- a/spec/services/task_service_spec.rb +++ b/spec/services/task_service_spec.rb @@ -45,6 +45,23 @@ describe TaskService, services: true do is_expected_to_not_create_task { service.reassigned_issue(assigned_issue, author) } end end + + describe '#mark_as_done' do + let!(:first_pending_task) do + create(:pending_assigned_task, user: john_doe, project: project, target: assigned_issue, author: author) + end + + let!(:second_pending_task) do + create(:pending_assigned_task, user: john_doe, project: project, target: assigned_issue, author: author) + end + + it 'marks related pending tasks to the target for the user as done' do + service.mark_as_done(assigned_issue, john_doe) + + expect(first_pending_task.reload.done?).to eq true + expect(second_pending_task.reload.done?).to eq true + end + end end def is_expected_to_create_pending_task(attributes = {}) |