validate length of label.title

+ add test for label.title length validation
This commit is contained in:
Tomáš Kukrál 2016-08-11 09:37:09 +02:00 committed by Tomáš Kukrál
parent 8ab94120ee
commit 7808c9cb50
3 changed files with 7 additions and 0 deletions

View file

@ -26,6 +26,7 @@ class Label < ActiveRecord::Base
# Don't allow ',' for label titles
validates :title, presence: true, format: { with: /\A[^,]+\z/ }
validates :title, uniqueness: { scope: [:group_id, :project_id] }
validates :title, length: { maximum: 255 }
default_scope { order(title: :asc) }

View file

@ -0,0 +1,4 @@
---
title: "Validate label's title length"
merge_request: 5767
author: Tomáš Kukrál

View file

@ -31,12 +31,14 @@ describe Label, models: true do
it 'validates title' do
is_expected.not_to allow_value('G,ITLAB').for(:title)
is_expected.not_to allow_value('').for(:title)
is_expected.not_to allow_value('s' * 256).for(:title)
is_expected.to allow_value('GITLAB').for(:title)
is_expected.to allow_value('gitlab').for(:title)
is_expected.to allow_value('G?ITLAB').for(:title)
is_expected.to allow_value('G&ITLAB').for(:title)
is_expected.to allow_value("customer's request").for(:title)
is_expected.to allow_value('s' * 255).for(:title)
end
end