Commit f7844a11 authored by Long Nguyen's avatar Long Nguyen

Code refactor and fix broken spec

parent d6d1daf4
......@@ -42,7 +42,7 @@ module Issues
def create_new_issue
new_params = { id: nil, iid: nil, label_ids: cloneable_label_ids,
milestone: cloneable_milestone_id,
milestone_id: cloneable_milestone_id,
project: @new_project, author: @old_issue.author,
description: rewrite_content(@old_issue.description) }
......@@ -51,11 +51,13 @@ module Issues
end
def cloneable_label_ids
@new_project.labels.where(title: @old_issue.labels.pluck(:title)).pluck(:id)
@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))
@new_project.milestones
.find_by(title: @old_issue.milestone.try(:title)).try(:id)
end
def rewrite_notes
......
......@@ -7,7 +7,9 @@ describe Issues::MoveService, services: true do
let(:description) { 'Some issue description' }
let(:old_project) { create(:project) }
let(:new_project) { create(:project) }
let!(:milestone1) { create(:milestone, project_id: old_project.id, title: 'v9.0') }
let!(:milestone1) do
create(:milestone, project_id: old_project.id, title: 'v9.0')
end
let(:old_issue) do
create(:issue, title: title, description: description,
......@@ -23,10 +25,12 @@ describe Issues::MoveService, services: true do
old_project.team << [user, :reporter]
new_project.team << [user, :reporter]
create(:milestone, project_id: new_project.id, title: 'v9.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')
['label1', 'label2'].each do |label|
old_issue.labels << create(:label,
project_id: old_project.id,
title: label
)
end
new_project.labels << create(:label, title: 'label1')
new_project.labels << create(:label, title: 'label2')
......@@ -35,6 +39,10 @@ describe Issues::MoveService, services: true do
describe '#execute' do
shared_context 'issue move executed' do
let!(:milestone2) do
create(:milestone, project_id: new_project.id, title: 'v9.0')
end
let!(:new_issue) { move_service.execute(old_issue, new_project) }
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