Marks pending tasks for an user as done when he close the MR

parent 7bed6ee2
......@@ -9,6 +9,7 @@ module MergeRequests
event_service.close_mr(merge_request, current_user)
create_note(merge_request)
notification_service.close_mr(merge_request, current_user)
task_service.close_merge_request(merge_request, current_user)
execute_hooks(merge_request, 'close')
end
......
......@@ -38,7 +38,15 @@ class TaskService
new_issuable(merge_request, current_user)
end
# When we reassign an merge request we should:
# When close a merge request we should:
#
# * mark all pending tasks related to the target for the current user as done
#
def close_merge_request(merge_request, current_user)
mark_as_done(merge_request, current_user)
end
# When we reassign a merge request we should:
#
# * creates a pending task for new assignee if merge request is assigned
#
......
......@@ -5,6 +5,9 @@ describe MergeRequests::CloseService, services: true do
let(:user2) { create(:user) }
let(:merge_request) { create(:merge_request, assignee: user2) }
let(:project) { merge_request.project }
let!(:pending_task) do
create(:pending_assigned_task, user: user, project: project, target: merge_request, author: user2)
end
before do
project.team << [user, :master]
......@@ -41,6 +44,10 @@ describe MergeRequests::CloseService, services: true do
note = @merge_request.notes.last
expect(note.note).to include 'Status changed to closed'
end
it 'marks pending tasks as done' do
expect(pending_task.reload).to be_done
end
end
end
end
......@@ -136,6 +136,23 @@ describe TaskService, services: true do
end
end
describe '#close_merge_request' do
let!(:first_pending_task) do
create(:pending_assigned_task, user: john_doe, project: project, target: mr_assigned, author: author)
end
let!(:second_pending_task) do
create(:pending_assigned_task, user: john_doe, project: project, target: mr_assigned, author: author)
end
it 'marks related pending tasks to the target for the user as done' do
service.close_merge_request(mr_assigned, john_doe)
expect(first_pending_task.reload).to be_done
expect(second_pending_task.reload).to be_done
end
end
describe '#reassigned_merge_request' do
it 'creates a pending task for new assignee' do
mr_unassigned.update_attribute(:assignee, john_doe)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment