Commit f7844a11 authored by Long Nguyen's avatar Long Nguyen

Code refactor and fix broken spec

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