Commit fbb5a8b0 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use a new issue create service when moving an issue

parent 57eb3954
...@@ -4,7 +4,7 @@ module Issues ...@@ -4,7 +4,7 @@ module Issues
super(project, current_user, params) super(project, current_user, params)
@issue_old = issue @issue_old = issue
@issue_new = @issue_old.dup @issue_new = nil
@project_old = @project @project_old = @project
@project_new = Project.find(new_project_id) if new_project_id @project_new = Project.find(new_project_id) if new_project_id
end end
...@@ -42,8 +42,18 @@ module Issues ...@@ -42,8 +42,18 @@ module Issues
end end
def open_new_issue def open_new_issue
new_description = rewrite_references(@issue_old, @issue_old.description) create_service = CreateService.new(@project_new, current_user, new_issue_params)
@issue_new.update(project: @project_new, description: new_description) @issue_new = create_service.execute
end
def new_issue_params
new_params = { id: nil, iid: nil, milestone_id: nil, label_ids: [],
project_id: @project_new.id,
author_id: @issue_old.author_id,
description: rewrite_references(@issue_old),
updated_by_id: current_user.id }
params.merge(new_params)
end end
def rewrite_notes def rewrite_notes
...@@ -68,9 +78,9 @@ module Issues ...@@ -68,9 +78,9 @@ 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, text) def rewrite_references(mentionable)
new_content = text.dup
references = mentionable.all_references references = mentionable.all_references
new_content = mentionable_content(mentionable).dup
[:issues, :merge_requests, :milestones].each do |type| [:issues, :merge_requests, :milestones].each do |type|
references.public_send(type).each do |mentioned| references.public_send(type).each do |mentioned|
...@@ -81,5 +91,14 @@ module Issues ...@@ -81,5 +91,14 @@ module Issues
new_content new_content
end end
def mentionable_content(mentionable)
case mentionable
when Issue then mentionable.description
when Note then mentionable.note
else
raise 'Unexpected mentionable while moving an issue'
end
end
end end
end end
...@@ -68,6 +68,11 @@ describe Issues::MoveService, services: true do ...@@ -68,6 +68,11 @@ describe Issues::MoveService, services: true do
it 'persists new issue' do it 'persists new issue' do
expect(new_issue.persisted?).to be true expect(new_issue.persisted?).to be true
end end
it 'persist all changes' do
expect(old_issue.changed?).to be false
expect(new_issue.changed?).to be false
end
end end
context 'issue with notes' do context 'issue with 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