diff options
Diffstat (limited to 'spec/services/issuable/clone/attributes_rewriter_spec.rb')
-rw-r--r-- | spec/services/issuable/clone/attributes_rewriter_spec.rb | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/spec/services/issuable/clone/attributes_rewriter_spec.rb b/spec/services/issuable/clone/attributes_rewriter_spec.rb index 9111b19d7b7..fb520f828fa 100644 --- a/spec/services/issuable/clone/attributes_rewriter_spec.rb +++ b/spec/services/issuable/clone/attributes_rewriter_spec.rb @@ -89,7 +89,7 @@ describe Issuable::Clone::AttributesRewriter do create_event(milestone1_project1) create_event(milestone2_project1) - create_event(milestone1_project1, 'remove') + create_event(nil, 'remove') create_event(milestone3_project1) end @@ -101,7 +101,7 @@ describe Issuable::Clone::AttributesRewriter do expect_milestone_event(new_issue_milestone_events.first, milestone: milestone1_project2, action: 'add', state: 'opened') expect_milestone_event(new_issue_milestone_events.second, milestone: milestone2_project2, action: 'add', state: 'opened') - expect_milestone_event(new_issue_milestone_events.third, milestone: milestone1_project2, action: 'remove', state: 'opened') + expect_milestone_event(new_issue_milestone_events.third, milestone: nil, action: 'remove', state: 'opened') end def create_event(milestone, action = 'add') @@ -109,10 +109,32 @@ describe Issuable::Clone::AttributesRewriter do end def expect_milestone_event(event, expected_attrs) - expect(event.milestone_id).to eq(expected_attrs[:milestone].id) + expect(event.milestone_id).to eq(expected_attrs[:milestone]&.id) expect(event.action).to eq(expected_attrs[:action]) expect(event.state).to eq(expected_attrs[:state]) end end + + context 'with existing state events' do + let!(:event1) { create(:resource_state_event, issue: original_issue, state: 'opened') } + let!(:event2) { create(:resource_state_event, issue: original_issue, state: 'closed') } + let!(:event3) { create(:resource_state_event, issue: original_issue, state: 'reopened') } + + it 'copies existing state events as expected' do + subject.execute + + state_events = new_issue.reload.resource_state_events + expect(state_events.size).to eq(3) + + expect_state_event(state_events.first, issue: new_issue, state: 'opened') + expect_state_event(state_events.second, issue: new_issue, state: 'closed') + expect_state_event(state_events.third, issue: new_issue, state: 'reopened') + end + + def expect_state_event(event, expected_attrs) + expect(event.issue_id).to eq(expected_attrs[:issue]&.id) + expect(event.state).to eq(expected_attrs[:state]) + end + end end end |