Commit cdfb639a authored by Thong Kuah's avatar Thong Kuah

Merge branch 'issue_296567' into 'master'

Prevent error when promoting issues to epics

See merge request gitlab-org/gitlab!60860
parents 1b59d0e7 70aec3e4
...@@ -73,12 +73,17 @@ module Issuable ...@@ -73,12 +73,17 @@ module Issuable
copy_events(ResourceStateEvent.table_name, original_entity.resource_state_events) do |event| copy_events(ResourceStateEvent.table_name, original_entity.resource_state_events) do |event|
event.attributes event.attributes
.except('id') .except(*blocked_state_event_attributes)
.merge(entity_key => new_entity.id, .merge(entity_key => new_entity.id,
'state' => ResourceStateEvent.states[event.state]) 'state' => ResourceStateEvent.states[event.state])
end end
end end
# Overriden on EE::Issuable::Clone::AttributesRewriter
def blocked_state_event_attributes
['id']
end
def event_attributes_with_milestone(event, milestone) def event_attributes_with_milestone(event, milestone)
event.attributes event.attributes
.except('id') .except('id')
......
...@@ -15,6 +15,11 @@ module EE ...@@ -15,6 +15,11 @@ module EE
private private
override :blocked_state_event_attributes
def blocked_state_event_attributes
super.push('issue_id')
end
def copy_resource_weight_events def copy_resource_weight_events
return unless both_respond_to?(:resource_weight_events) return unless both_respond_to?(:resource_weight_events)
......
---
title: Prevent errors when promoting issues to epics
merge_request: 60860
author:
type: fixed
...@@ -40,6 +40,24 @@ RSpec.describe Issuable::Clone::AttributesRewriter do ...@@ -40,6 +40,24 @@ RSpec.describe Issuable::Clone::AttributesRewriter do
end end
end end
context 'when cloning state events' do
before do
create(:resource_state_event, issue: original_issue)
end
it 'ignores issue_id attribute' do
milestone = create(:milestone, title: 'milestone', group: group)
original_issue.update(milestone: milestone)
subject.execute
latest_state_event = ResourceStateEvent.last
expect(latest_state_event).to be_valid
expect(latest_state_event.issue_id).to be_nil
expect(latest_state_event.epic).to eq(new_epic)
end
end
context 'when issue has weight events' do context 'when issue has weight events' do
it 'ignores copying weight events' do it 'ignores copying weight events' do
create_list(:resource_weight_event, 2, issue: original_issue) create_list(:resource_weight_event, 2, issue: original_issue)
......
...@@ -130,6 +130,25 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do ...@@ -130,6 +130,25 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
end end
end end
context 'when issue has resource state event' do
let!(:issue_event) { create(:resource_state_event, issue: issue) }
it 'does not raise error' do
expect { subject.execute(issue) }.not_to raise_error
end
it 'promotes issue successfully' do
epic = subject.execute(issue)
resource_state_event = epic.resource_state_events.first
expect(epic.title).to eq(issue.title)
expect(issue.promoted_to_epic).to eq(epic)
expect(resource_state_event.issue_id).to eq(nil)
expect(resource_state_event.epic_id).to eq(epic.id)
expect(resource_state_event.state).to eq(issue_event.state)
end
end
context 'when promoting issue to a different group' do context 'when promoting issue to a different group' do
it 'creates a new epic with correct attributes' do it 'creates a new epic with correct attributes' do
epic = subject.execute(issue, new_group) epic = subject.execute(issue, new_group)
......
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