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

parent e81061a2
...@@ -3,6 +3,7 @@ module Issues ...@@ -3,6 +3,7 @@ module Issues
def execute(issue, commit = nil) def execute(issue, commit = nil)
if project.jira_tracker? && project.jira_service.active if project.jira_tracker? && project.jira_service.active
project.jira_service.execute(commit, issue) project.jira_service.execute(commit, issue)
task_service.close_issue(issue, current_user)
return issue return issue
end end
...@@ -10,6 +11,7 @@ module Issues ...@@ -10,6 +11,7 @@ module Issues
event_service.close_issue(issue, current_user) event_service.close_issue(issue, current_user)
create_note(issue, commit) create_note(issue, commit)
notification_service.close_issue(issue, current_user) notification_service.close_issue(issue, current_user)
task_service.close_issue(issue, current_user)
execute_hooks(issue, 'close') execute_hooks(issue, 'close')
end end
......
...@@ -16,6 +16,14 @@ class TaskService ...@@ -16,6 +16,14 @@ class TaskService
end end
end end
# When close an issue we should:
#
# * mark all pending tasks related to the target for the current user as done
#
def close_issue(issue, current_user)
mark_as_done(issue, current_user)
end
# When we reassign an issue we should: # When we reassign an issue we should:
# #
# * creates a pending task for new assignee if issue is assigned # * creates a pending task for new assignee if issue is assigned
......
...@@ -5,6 +5,9 @@ describe Issues::CloseService, services: true do ...@@ -5,6 +5,9 @@ describe Issues::CloseService, services: true do
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:issue) { create(:issue, assignee: user2) } let(:issue) { create(:issue, assignee: user2) }
let(:project) { issue.project } let(:project) { issue.project }
let!(:pending_task) do
create(:pending_assigned_task, user: user, project: project, target: issue, author: user2)
end
before do before do
project.team << [user, :master] project.team << [user, :master]
...@@ -32,6 +35,10 @@ describe Issues::CloseService, services: true do ...@@ -32,6 +35,10 @@ describe Issues::CloseService, services: true do
note = @issue.notes.last note = @issue.notes.last
expect(note.note).to include "Status changed to closed" expect(note.note).to include "Status changed to closed"
end end
it 'marks pending tasks as done' do
expect(pending_task.reload).to be_done
end
end end
context "external issue tracker" do context "external issue tracker" do
...@@ -42,6 +49,7 @@ describe Issues::CloseService, services: true do ...@@ -42,6 +49,7 @@ describe Issues::CloseService, services: true do
it { expect(@issue).to be_valid } it { expect(@issue).to be_valid }
it { expect(@issue).to be_opened } it { expect(@issue).to be_opened }
it { expect(pending_task.reload).to be_pending }
end end
end end
end end
...@@ -31,6 +31,23 @@ describe TaskService, services: true do ...@@ -31,6 +31,23 @@ describe TaskService, services: true do
end end
end end
describe '#close_issue' 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.close_issue(assigned_issue, john_doe)
expect(first_pending_task.reload.done?).to eq true
expect(second_pending_task.reload.done?).to eq true
end
end
describe '#reassigned_issue' do describe '#reassigned_issue' do
it 'creates a pending task for new assignee' do it 'creates a pending task for new assignee' do
unassigned_issue.update_attribute(:assignee, john_doe) unassigned_issue.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