Commit 949ff817 authored by Luke Duncalfe's avatar Luke Duncalfe Committed by Bob Van Landuyt

Bugfix duplicate design comments during copy

This change fixes comments on designs being duplicated during an issue
move.

https://gitlab.com/gitlab-org/gitlab/-/issues/13426
parent 4b7e5399
...@@ -246,7 +246,7 @@ module DesignManagement ...@@ -246,7 +246,7 @@ module DesignManagement
new_designs = DesignManagement::Design.unscoped.find(design_ids) new_designs = DesignManagement::Design.unscoped.find(design_ids)
# Execute another query to filter only designs with notes # Execute another query to filter only designs with notes
DesignManagement::Design.unscoped.where(id: designs).joins(:notes).find_each(batch_size: 100) do |old_design| DesignManagement::Design.unscoped.where(id: designs).joins(:notes).distinct.find_each(batch_size: 100) do |old_design|
new_design = new_designs.find { |d| d.filename == old_design.filename } new_design = new_designs.find { |d| d.filename == old_design.filename }
Notes::CopyService.new(current_user, old_design, new_design).execute Notes::CopyService.new(current_user, old_design, new_design).execute
......
...@@ -133,18 +133,26 @@ RSpec.describe DesignManagement::CopyDesignCollection::CopyService, :clean_gitla ...@@ -133,18 +133,26 @@ RSpec.describe DesignManagement::CopyDesignCollection::CopyService, :clean_gitla
end end
it 'copies design notes correctly', :aggregate_failures, :sidekiq_inline do it 'copies design notes correctly', :aggregate_failures, :sidekiq_inline do
note = create(:diff_note_on_design, noteable: designs.first, project: project) old_notes = [
create(:diff_note_on_design, note: 'first note', noteable: designs.first, project: project, author: create(:user)),
create(:diff_note_on_design, note: 'second note', noteable: designs.first, project: project, author: create(:user))
]
matchers = old_notes.map do |note|
have_attributes(
note.attributes.slice(
:type,
:author_id,
:note,
:position
)
)
end
expect { subject }.to change { Note.count }.by(1) expect { subject }.to change { Note.count }.by(2)
new_note = target_issue.designs.first.notes.first new_notes = target_issue.designs.first.notes.fresh
expect(new_note).to have_attributes( expect(new_notes).to match_array(matchers)
type: note.type,
author_id: note.author_id,
note: note.note,
position: note.position
)
end end
it 'links the LfsObjects' do it 'links the LfsObjects' 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