diff --git a/app/models/label.rb b/app/models/label.rb index 5c01c15e5af020504b588ebf1e05461c89037491..5b6b9a7a736798ca84c9fe27a02dbf8fa95adcb8 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 0000000000000000000000000000000000000000..7abf1c4d05acb9d56129fba6d16ad3047911f6b1 --- /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 0c163659a717ab11279244194eea4a5bb2a4f003..a9139f7d4ab22b4901bb270a9d7d185cae2d9fad 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