Commit 6524ec5d authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'label-length-validation' into 'master'

Validate label's title length

See merge request !5767
parents 83fd7ea5 7808c9cb
...@@ -26,6 +26,7 @@ class Label < ActiveRecord::Base ...@@ -26,6 +26,7 @@ class Label < ActiveRecord::Base
# Don't allow ',' for label titles # Don't allow ',' for label titles
validates :title, presence: true, format: { with: /\A[^,]+\z/ } validates :title, presence: true, format: { with: /\A[^,]+\z/ }
validates :title, uniqueness: { scope: [:group_id, :project_id] } validates :title, uniqueness: { scope: [:group_id, :project_id] }
validates :title, length: { maximum: 255 }
default_scope { order(title: :asc) } default_scope { order(title: :asc) }
......
---
title: "Validate label's title length"
merge_request: 5767
author: Tomáš Kukrál
...@@ -31,12 +31,14 @@ describe Label, models: true do ...@@ -31,12 +31,14 @@ describe Label, models: true do
it 'validates title' do it 'validates title' do
is_expected.not_to allow_value('G,ITLAB').for(:title) is_expected.not_to allow_value('G,ITLAB').for(:title)
is_expected.not_to allow_value('').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('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('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("customer's request").for(:title)
is_expected.to allow_value('s' * 255).for(:title)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment