Add restriction to number of permitted priorities per project label
This commit is contained in:
parent
67314e95ae
commit
99e928f103
|
@ -1,8 +1,11 @@
|
|||
class ProjectLabel < Label
|
||||
NUMBER_OF_PRIORITIES = 1
|
||||
|
||||
belongs_to :project
|
||||
|
||||
validates :project, presence: true
|
||||
|
||||
validate :permitted_numbers_of_priorities
|
||||
validate :title_must_not_exist_at_group_level
|
||||
|
||||
delegate :group, to: :project, allow_nil: true
|
||||
|
@ -20,4 +23,10 @@ class ProjectLabel < Label
|
|||
errors.add(:title, :label_already_exists_at_group_level, group: group.name)
|
||||
end
|
||||
end
|
||||
|
||||
def permitted_numbers_of_priorities
|
||||
if priorities && priorities.size >= NUMBER_OF_PRIORITIES
|
||||
errors.add(:priorities, 'Number of permitted priorities exceeded')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,7 +48,18 @@ describe ProjectLabel, models: true do
|
|||
|
||||
project_label.valid?
|
||||
|
||||
expect(project_label .errors[:title]).to be_empty
|
||||
expect(project_label.errors[:title]).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'when attempting to add more than one priority to the project label' do
|
||||
it 'returns error' do
|
||||
subject.priorities.build
|
||||
subject.priorities.build
|
||||
|
||||
subject.valid?
|
||||
|
||||
expect(subject.errors[:priorities]).to include 'Number of permitted priorities exceeded'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue