Commit efd82517 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Minor refactoring of issue move service and specs

parent c2d4060f
...@@ -79,28 +79,30 @@ module Issues ...@@ -79,28 +79,30 @@ module Issues
SystemNoteService.noteable_moved(:to, @issue_old, @project_old, @issue_new, @current_user) SystemNoteService.noteable_moved(:to, @issue_old, @project_old, @issue_new, @current_user)
end end
def rewrite_references(mentionable) def rewrite_references(noteable)
references = mentionable.all_references references = noteable.all_references
new_content = mentionable_content(mentionable).dup new_content = noteable_content(noteable).dup
cross_project_refs = [:issues, :merge_requests, :milestones, cross_project_mentionables = [:issues, :merge_requests, :milestones,
:snippets, :commits, :commit_ranges] :snippets, :commits, :commit_ranges]
cross_project_refs.each do |type| cross_project_mentionables.each do |type|
references.public_send(type).each do |mentioned| references.public_send(type).each do |mentionable|
new_content.gsub!(mentioned.to_reference, new_content.gsub!(mentionable.to_reference,
mentioned.to_reference(@project_new)) mentionable.to_reference(@project_new))
end end
end end
new_content new_content
end end
def mentionable_content(mentionable) def noteable_content(noteable)
case mentionable case noteable
when Issue then mentionable.description when Issue
when Note then mentionable.note noteable.description
when Note
noteable.note
else else
raise 'Unexpected mentionable while moving an issue' raise 'Unexpected noteable while moving an issue'
end end
end end
end end
......
...@@ -101,6 +101,8 @@ describe Issues::MoveService, services: true do ...@@ -101,6 +101,8 @@ describe Issues::MoveService, services: true do
{ system: false, note: 'Some comment 2' }] { system: false, note: 'Some comment 2' }]
end end
let(:notes_contents) { notes_params.map { |n| n[:note] } }
before do before do
note_params = { noteable: old_issue, project: old_project, author: author } note_params = { noteable: old_issue, project: old_project, author: author }
notes_params.each do |note| notes_params.each do |note|
...@@ -115,8 +117,7 @@ describe Issues::MoveService, services: true do ...@@ -115,8 +117,7 @@ describe Issues::MoveService, services: true do
let(:user_notes) { all_notes.user } let(:user_notes) { all_notes.user }
it 'rewrites existing notes in valid order' do it 'rewrites existing notes in valid order' do
expect(all_notes.pluck(:note).first(3)) expect(all_notes.pluck(:note).first(3)).to eq notes_contents
.to eq notes_params.map { |n| n[:note] }
end end
it 'adds a system note about move after rewritten notes' do it 'adds a system note about move after rewritten notes' do
......
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