add a uniq constraints on issues and mrs labels

This commit is contained in:
Antoine Huret 2019-04-01 09:09:49 +00:00 committed by Sean McGivern
parent e5aa2d8824
commit 5e10b61129
4 changed files with 30 additions and 1 deletions

View File

@ -113,7 +113,7 @@ class IssuableBaseService < BaseService
new_label_ids -= remove_label_ids if remove_label_ids
end
new_label_ids
new_label_ids.uniq
end
def available_labels

View File

@ -0,0 +1,5 @@
---
title: add a uniq constraints on issues and mrs labels
merge_request: 25435
author: Antoine Huret
type: fixed

View File

@ -138,6 +138,20 @@ describe Issues::CreateService do
end
end
context 'when duplicate label titles are given' do
let(:label) { create(:label, project: project) }
let(:opts) do
{ title: 'Title',
description: 'Description',
labels: [label.title, label.title] }
end
it 'assigns the label once' do
expect(issue.labels).to contain_exactly(label)
end
end
it 'executes issue hooks when issue is not confidential' do
opts = { title: 'Title', description: 'Description', confidential: false }

View File

@ -592,6 +592,16 @@ describe Issues::UpdateService, :mailer do
expect(result.label_ids).not_to include(label.id)
end
end
context 'when duplicate label titles are given' do
let(:params) do
{ labels: [label3.title, label3.title] }
end
it 'assigns the label once' do
expect(result.labels).to contain_exactly(label3)
end
end
end
context 'updating asssignee_id' do