diff options
-rw-r--r-- | app/models/label.rb | 1 | ||||
-rw-r--r-- | changelogs/unreleased/validate-title-length.yml | 4 | ||||
-rw-r--r-- | spec/models/label_spec.rb | 2 |
3 files changed, 7 insertions, 0 deletions
diff --git a/app/models/label.rb b/app/models/label.rb index 5c01c15e5af..5b6b9a7a736 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -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) } diff --git a/changelogs/unreleased/validate-title-length.yml b/changelogs/unreleased/validate-title-length.yml new file mode 100644 index 00000000000..7abf1c4d05a --- /dev/null +++ b/changelogs/unreleased/validate-title-length.yml @@ -0,0 +1,4 @@ +--- +title: "Validate label's title length" +merge_request: 5767 +author: Tomáš Kukrál diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb index 0c163659a71..a9139f7d4ab 100644 --- a/spec/models/label_spec.rb +++ b/spec/models/label_spec.rb @@ -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 |