Commit a066f3e0 authored by Sean McGivern's avatar Sean McGivern

Merge branch '7869-update-previous-epic-when-issue-moves-to-new-epic' into 'master'

Update previous epic milestone dates when issue switches epic

Closes #7869

See merge request gitlab-org/gitlab-ee!7809
parents f0396ba2 9da67fb0
module EpicIssues
class CreateService < IssuableLinks::CreateService
def execute
result = super
issuable.update_start_and_due_dates
result
end
private
# rubocop: disable CodeReuse/ActiveRecord
def relate_issues(referenced_issue)
link = EpicIssue.find_or_initialize_by(issue: referenced_issue)
params = if link.persisted?
{ issue_moved: true, original_epic: link.epic }
else
{}
end
affected_epics = [issuable]
if link.persisted?
affected_epics << link.epic
params = { issue_moved: true, original_epic: link.epic }
else
params = {}
end
link.epic = issuable
link.move_to_start
link.save!
affected_epics.each(&:update_start_and_due_dates)
yield params
end
# 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
shared_examples 'returns success' do
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(created_link).to have_attributes(epic: epic)
......@@ -141,7 +142,7 @@ describe EpicIssues::CreateService do
# and we insert 5 issues instead of 1 which we do for control count
expect { described_class.new(epic, user, params).execute }
.not_to exceed_query_limit(control_count)
.with_threshold(24)
.with_threshold(28)
end
end
......@@ -228,6 +229,18 @@ describe EpicIssues::CreateService do
expect { subject }.to change { Note.count }.from(0).to(3)
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
subject
......@@ -268,14 +281,6 @@ describe EpicIssues::CreateService do
include_examples 'returns an error'
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
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