Commit 247ae960 authored by Long Nguyen's avatar Long Nguyen

Allow to assign labels and milestone to target project when moving issue

parent df8fda60
......@@ -41,7 +41,8 @@ module Issues
private
def create_new_issue
new_params = { id: nil, iid: nil, label_ids: [], milestone: nil,
new_params = { id: nil, iid: nil, label_ids: cloneable_label_ids,
milestone: cloneable_milestone_id,
project: @new_project, author: @old_issue.author,
description: rewrite_content(@old_issue.description) }
......@@ -49,6 +50,14 @@ module Issues
CreateService.new(@new_project, @current_user, new_params).execute
end
def cloneable_label_ids
@new_project.labels.where(title: @old_issue.labels.pluck(:title)).pluck(:id)
end
def cloneable_milestone_id
@new_project.milestones.find_by(title: @old_issue.milestone.try(:title))
end
def rewrite_notes
@old_issue.notes.find_each do |note|
new_note = note.dup
......
......@@ -21,6 +21,15 @@ describe Issues::MoveService, services: true do
before do
old_project.team << [user, :reporter]
new_project.team << [user, :reporter]
create(:milestone, project_id: old_project.id, title: 'v1.0')
create(:milestone, project_id: new_project.id, title: 'v1.0')
old_issue.labels << create(:label, project_id: old_project.id, title: 'label1')
old_issue.labels << create(:label, project_id: old_project.id, title: 'label2')
new_project.labels << create(:label, title: 'label1')
new_project.labels << create(:label, title: 'label2')
end
end
......@@ -39,6 +48,17 @@ describe Issues::MoveService, services: true do
expect(new_issue.project).to eq new_project
end
it 'assigns milestone to new issue' do
expect(new_issue.reload.milestone.title).to eq 'v1.0'
end
it 'assign labels to new issue' do
expected_label_titles = new_issue.reload.labels.map(&:title)
expect(expected_label_titles).to include 'label1'
expect(expected_label_titles).to include 'label2'
expect(expected_label_titles.size).to eq 2
end
it 'rewrites issue title' do
expect(new_issue.title).to eq title
end
......
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