Commit 14c983fb authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add implementation that rewrites issue notes when moving

parent c8e7d1ed
...@@ -15,9 +15,19 @@ module Issues ...@@ -15,9 +15,19 @@ module Issues
def execute def execute
return unless move? return unless move?
# New issue tasks
#
open_new_issue open_new_issue
rewrite_notes rewrite_notes
add_moved_from_note
# Old issue tasks
#
close_old_issue close_old_issue
add_moved_to_note
# Notifications
#
notify_participants notify_participants
@issue_new @issue_new
...@@ -40,25 +50,28 @@ module Issues ...@@ -40,25 +50,28 @@ module Issues
def open_new_issue def open_new_issue
@issue_new.project = @project_new @issue_new.project = @project_new
@issue_new.save! @issue_new.save!
add_note_moved_from
end end
def rewrite_notes def rewrite_notes
@issue_old.notes.find_each do |note|
note_new = note.dup
note_new.project = @project_new
note_new.noteable = @issue_new
note_new.save!
end
end end
def close_old_issue def close_old_issue
add_note_moved_to
end end
def notify_participants def notify_participants
end end
def add_note_moved_from def add_moved_from_note
SystemNoteService.noteable_moved(:from, @issue_new, @project_new, @issue_old, @current_user) SystemNoteService.noteable_moved(:from, @issue_new, @project_new, @issue_old, @current_user)
end end
def add_note_moved_to def add_moved_to_note
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
end end
......
...@@ -2,15 +2,15 @@ require 'spec_helper' ...@@ -2,15 +2,15 @@ require 'spec_helper'
describe Issues::MoveService, services: true do describe Issues::MoveService, services: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:issue) { create(:issue, title: 'Some issue', description: 'Some issue description') } let(:title) { 'Some issue' }
let(:current_project) { issue.project } let(:description) { 'Some issue description' }
let(:old_issue) { create(:issue, title: title, description: description) }
let(:current_project) { old_issue.project }
let(:new_project) { create(:project) } let(:new_project) { create(:project) }
let(:move_params) { { 'move_to_project_id' => new_project.id } } let(:move_params) { { 'move_to_project_id' => new_project.id } }
let(:move_service) { described_class.new(current_project, user, move_params, issue) } let(:move_service) { described_class.new(current_project, user, move_params, old_issue) }
before do before { current_project.team << [user, :master] }
current_project.team << [user, :master]
end
context 'issue movable' do context 'issue movable' do
describe '#move?' do describe '#move?' do
...@@ -19,20 +19,59 @@ describe Issues::MoveService, services: true do ...@@ -19,20 +19,59 @@ describe Issues::MoveService, services: true do
end end
describe '#execute' do describe '#execute' do
shared_context 'issue move executed' do
let!(:new_issue) { move_service.execute } let!(:new_issue) { move_service.execute }
end
it 'should create a new issue in a new project' do context 'generic issue' do
include_context 'issue move executed'
it 'creates a new issue in a new project' do
expect(new_issue.project).to eq new_project expect(new_issue.project).to eq new_project
end end
it 'should add system note to old issue' do it 'rewrites issue title' do
expect(issue.notes.last.note).to match /^Moved to/ expect(new_issue.title).to eq title
end
it 'rewrites issue description' do
expect(new_issue.description).to include description
end end
it 'should add system note to new issue' do it 'adds system note to old issue at the end' do
expect(old_issue.notes.last.note).to match /^Moved to/
end
it 'adds system note to new issue at the end' do
expect(new_issue.notes.last.note).to match /^Moved from/ expect(new_issue.notes.last.note).to match /^Moved from/
end end
end end
context 'notes exist' do
let(:note_contents) do
['Some system note 1', 'Some comment', 'Some system note 2']
end
before do
note_params = { noteable: old_issue, project: current_project, author: user}
create(:system_note, note_params.merge(note: note_contents.first))
create(:note, note_params.merge(note: note_contents.second))
create(:system_note, note_params.merge(note: note_contents.third))
end
include_context 'issue move executed'
let(:new_notes) { new_issue.notes.order('id ASC').pluck(:note) }
it 'rewrites existing system notes in valid order' do
expect(new_notes.first(3)).to eq note_contents
end
it 'adds a system note about move after rewritten notes' do
expect(new_notes.last).to match /^Moved from/
end
end
end
end end
context 'issue not movable' do context 'issue not movable' 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