Validates uniqueness of title unless label is a template
This commit is contained in:
parent
bdb7bf4b51
commit
9463551ece
2 changed files with 3 additions and 4 deletions
|
@ -26,10 +26,8 @@ class Label < ActiveRecord::Base
|
||||||
validates :project, presence: true, if: :project_label?
|
validates :project, presence: true, if: :project_label?
|
||||||
|
|
||||||
# Don't allow ',' for label titles
|
# Don't allow ',' for label titles
|
||||||
validates :title,
|
validates :title, presence: true, format: { with: /\A[^,]+\z/ }
|
||||||
presence: true,
|
validates :title, uniqueness: true, unless: :template?
|
||||||
format: { with: /\A[^,]+\z/ },
|
|
||||||
uniqueness: { scope: :project_id }
|
|
||||||
|
|
||||||
before_save :nullify_priority
|
before_save :nullify_priority
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ describe Label, models: true do
|
||||||
|
|
||||||
describe 'validation' do
|
describe 'validation' do
|
||||||
it { is_expected.to validate_presence_of(:project) }
|
it { is_expected.to validate_presence_of(:project) }
|
||||||
|
it { is_expected.to validate_uniqueness_of(:title) }
|
||||||
|
|
||||||
it 'validates color code' do
|
it 'validates color code' do
|
||||||
expect(label).not_to allow_value('G-ITLAB').for(:color)
|
expect(label).not_to allow_value('G-ITLAB').for(:color)
|
||||||
|
|
Loading…
Reference in a new issue