Commit 9da67fb0 authored by Mark Chao's avatar Mark Chao

Update previous epic milestone dates when issue's epic switches

Both the old and new epic should update their milestone dates
when an issue switches epic.
parent fea9b6aa
module EpicIssues module EpicIssues
class CreateService < IssuableLinks::CreateService class CreateService < IssuableLinks::CreateService
def execute
result = super
issuable.update_start_and_due_dates
result
end
private private
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def relate_issues(referenced_issue) def relate_issues(referenced_issue)
link = EpicIssue.find_or_initialize_by(issue: referenced_issue) link = EpicIssue.find_or_initialize_by(issue: referenced_issue)
params = if link.persisted? affected_epics = [issuable]
{ issue_moved: true, original_epic: link.epic }
else if link.persisted?
{} affected_epics << link.epic
end params = { issue_moved: true, original_epic: link.epic }
else
params = {}
end
link.epic = issuable link.epic = issuable
link.move_to_start link.move_to_start
link.save! link.save!
affected_epics.each(&:update_start_and_due_dates)
yield params yield params
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
---
title: Fix epic milestone dates incorrect after issue is linked to another epic
merge_request: 7809
author:
type: fixed
...@@ -22,7 +22,8 @@ describe EpicIssues::CreateService do ...@@ -22,7 +22,8 @@ describe EpicIssues::CreateService do
shared_examples 'returns success' do shared_examples 'returns success' do
let(:created_link) { EpicIssue.find_by!(issue_id: issue.id) } let(:created_link) { EpicIssue.find_by!(issue_id: issue.id) }
it 'creates a new relationship' do it 'creates a new relationship and updates epic' do
expect(epic).to receive(:update_start_and_due_dates)
expect { subject }.to change(EpicIssue, :count).from(1).to(2) expect { subject }.to change(EpicIssue, :count).from(1).to(2)
expect(created_link).to have_attributes(epic: epic) expect(created_link).to have_attributes(epic: epic)
...@@ -141,7 +142,7 @@ describe EpicIssues::CreateService do ...@@ -141,7 +142,7 @@ describe EpicIssues::CreateService do
# and we insert 5 issues instead of 1 which we do for control count # and we insert 5 issues instead of 1 which we do for control count
expect { described_class.new(epic, user, params).execute } expect { described_class.new(epic, user, params).execute }
.not_to exceed_query_limit(control_count) .not_to exceed_query_limit(control_count)
.with_threshold(24) .with_threshold(28)
end end
end end
...@@ -228,6 +229,18 @@ describe EpicIssues::CreateService do ...@@ -228,6 +229,18 @@ describe EpicIssues::CreateService do
expect { subject }.to change { Note.count }.from(0).to(3) expect { subject }.to change { Note.count }.from(0).to(3)
end end
it 'updates both old and new epic milestone dates' do
allow(EpicIssue).to receive(:find_or_initialize_by).with(issue: issue).and_wrap_original { |m, *args|
existing_epic_issue = m.call(*args)
expect(existing_epic_issue.epic).to receive(:update_start_and_due_dates)
existing_epic_issue
}
expect(another_epic).to receive(:update_start_and_due_dates)
subject
end
it 'creates a note correctly for the original epic' do it 'creates a note correctly for the original epic' do
subject subject
...@@ -268,14 +281,6 @@ describe EpicIssues::CreateService do ...@@ -268,14 +281,6 @@ describe EpicIssues::CreateService do
include_examples 'returns an error' include_examples 'returns an error'
end end
context 'refresh epic dates' do
it 'calls epic#update_start_and_due_dates' do
expect(epic).to receive(:update_start_and_due_dates)
assign_issue([valid_reference])
end
end
end end
end end
end end
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