diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-17 22:39:21 -0200 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-19 14:58:27 -0200 |
commit | 49ec98d1b2ca6f57f3f9434a0be0018fa5a53681 (patch) | |
tree | acef0f1ad0f9e5b1665b9e2c33f895754cbbc17a | |
parent | 301264beada6aaf7dd0e4244c3f41131f9b4f359 (diff) | |
download | gitlab-ce-49ec98d1b2ca6f57f3f9434a0be0018fa5a53681.tar.gz |
Recreates the label priorities when moving project to another group
-rw-r--r-- | app/services/labels/transfer_service.rb | 3 | ||||
-rw-r--r-- | spec/services/labels/transfer_service_spec.rb | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/app/services/labels/transfer_service.rb b/app/services/labels/transfer_service.rb index 04312c114ef..559d2860d97 100644 --- a/app/services/labels/transfer_service.rb +++ b/app/services/labels/transfer_service.rb @@ -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 diff --git a/spec/services/labels/transfer_service_spec.rb b/spec/services/labels/transfer_service_spec.rb index a72a05f6c99..cb09c16698a 100644 --- a/spec/services/labels/transfer_service_spec.rb +++ b/spec/services/labels/transfer_service_spec.rb @@ -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 |