Recreates the label priorities when moving project to another group

parent 301264be
......@@ -14,7 +14,7 @@ module Labels
return unless group.present?
Label.transaction do
labels_to_transfer = Label.where(id: label_links.select(:label_id).uniq)
labels_to_transfer = Label.where(id: label_links.select(:label_id))
labels_to_transfer.find_each do |label|
new_label_id = find_or_create_label!(label)
......@@ -22,6 +22,7 @@ module Labels
next if new_label_id == label.id
LabelLink.where(label_id: label.id).update_all(label_id: new_label_id)
LabelPriority.where(project_id: project.id, label_id: label.id).update_all(label_id: new_label_id)
end
end
end
......
......@@ -26,6 +26,16 @@ describe Labels::TransferService, services: true do
expect { service.execute }.to change(project.labels, :count).by(2)
end
it 'recreates label priorities related to the missing group labels' do
create(:label_priority, project: project, label: group_label_1, priority: 1)
service.execute
new_project_label = project.labels.find_by(title: group_label_1.title)
expect(new_project_label.id).not_to eq group_label_1.id
expect(new_project_label.priorities).not_to be_empty
end
it 'does not recreate missing group labels that are not applied to issues or merge requests' do
service.execute
......
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