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
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
......
......@@ -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
......
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