diff options
-rw-r--r-- | app/services/issues/move_service.rb | 32 | ||||
-rw-r--r-- | spec/services/issues/move_service_spec.rb | 5 |
2 files changed, 20 insertions, 17 deletions
diff --git a/app/services/issues/move_service.rb b/app/services/issues/move_service.rb index 782b8b6a430..a404a64cfe9 100644 --- a/app/services/issues/move_service.rb +++ b/app/services/issues/move_service.rb @@ -79,28 +79,30 @@ module Issues SystemNoteService.noteable_moved(:to, @issue_old, @project_old, @issue_new, @current_user) end - def rewrite_references(mentionable) - references = mentionable.all_references - new_content = mentionable_content(mentionable).dup - cross_project_refs = [:issues, :merge_requests, :milestones, - :snippets, :commits, :commit_ranges] - - cross_project_refs.each do |type| - references.public_send(type).each do |mentioned| - new_content.gsub!(mentioned.to_reference, - mentioned.to_reference(@project_new)) + def rewrite_references(noteable) + references = noteable.all_references + new_content = noteable_content(noteable).dup + cross_project_mentionables = [:issues, :merge_requests, :milestones, + :snippets, :commits, :commit_ranges] + + cross_project_mentionables.each do |type| + references.public_send(type).each do |mentionable| + new_content.gsub!(mentionable.to_reference, + mentionable.to_reference(@project_new)) end end new_content end - def mentionable_content(mentionable) - case mentionable - when Issue then mentionable.description - when Note then mentionable.note + def noteable_content(noteable) + case noteable + when Issue + noteable.description + when Note + noteable.note else - raise 'Unexpected mentionable while moving an issue' + raise 'Unexpected noteable while moving an issue' end end end diff --git a/spec/services/issues/move_service_spec.rb b/spec/services/issues/move_service_spec.rb index 596da74b572..cd051175612 100644 --- a/spec/services/issues/move_service_spec.rb +++ b/spec/services/issues/move_service_spec.rb @@ -101,6 +101,8 @@ describe Issues::MoveService, services: true do { system: false, note: 'Some comment 2' }] end + let(:notes_contents) { notes_params.map { |n| n[:note] } } + before do note_params = { noteable: old_issue, project: old_project, author: author } notes_params.each do |note| @@ -115,8 +117,7 @@ describe Issues::MoveService, services: true do let(:user_notes) { all_notes.user } it 'rewrites existing notes in valid order' do - expect(all_notes.pluck(:note).first(3)) - .to eq notes_params.map { |n| n[:note] } + expect(all_notes.pluck(:note).first(3)).to eq notes_contents end it 'adds a system note about move after rewritten notes' do |