diff --git a/app/models/label.rb b/app/models/label.rb index f43bebbf71b..be0c20479d5 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -26,10 +26,8 @@ class Label < ActiveRecord::Base validates :project, presence: true, if: :project_label? # Don't allow ',' for label titles - validates :title, - presence: true, - format: { with: /\A[^,]+\z/ }, - uniqueness: { scope: :project_id } + validates :title, presence: true, format: { with: /\A[^,]+\z/ } + validates :title, uniqueness: true, unless: :template? before_save :nullify_priority diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb index 5a5d1a5d60c..894021dc8e6 100644 --- a/spec/models/label_spec.rb +++ b/spec/models/label_spec.rb @@ -19,6 +19,7 @@ describe Label, models: true do describe 'validation' do it { is_expected.to validate_presence_of(:project) } + it { is_expected.to validate_uniqueness_of(:title) } it 'validates color code' do expect(label).not_to allow_value('G-ITLAB').for(:color)