From 2e7b9593949ca4c011ec79e298a96aca2311cede Mon Sep 17 00:00:00 2001 From: murin Date: Tue, 22 Oct 2024 15:25:32 +0300 Subject: Increase maximum size for custom field name --- app/models/custom_field.rb | 2 +- .../20241016120800_change_custom_fields_name_limit.rb | 9 +++++++++ test/unit/custom_field_test.rb | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20241016120800_change_custom_fields_name_limit.rb diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index ec8c5de8d..dae27480b 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -35,7 +35,7 @@ class CustomField < ApplicationRecord validates_presence_of :name, :field_format validates_uniqueness_of :name, :scope => :type, :case_sensitive => true - validates_length_of :name, :maximum => 30 + validates_length_of :name, maximum: 255 validates_length_of :regexp, maximum: 255 validates_inclusion_of :field_format, :in => proc {Redmine::FieldFormat.available_formats} diff --git a/db/migrate/20241016120800_change_custom_fields_name_limit.rb b/db/migrate/20241016120800_change_custom_fields_name_limit.rb new file mode 100644 index 000000000..07760e1ee --- /dev/null +++ b/db/migrate/20241016120800_change_custom_fields_name_limit.rb @@ -0,0 +1,9 @@ +class ChangeCustomFieldsNameLimit < ActiveRecord::Migration[7.2] + def up + change_column :custom_fields, :name, :string, limit: 255, default: '' + end + + def down + change_column :custom_fields, :name, :string, limit: 30, default: '' + end +end diff --git a/test/unit/custom_field_test.rb b/test/unit/custom_field_test.rb index 92d4d33af..d09d8863f 100644 --- a/test/unit/custom_field_test.rb +++ b/test/unit/custom_field_test.rb @@ -52,6 +52,11 @@ class CustomFieldTest < ActiveSupport::TestCase assert field.save end + def test_name_should_be_validated + field = CustomField.new(name: 'Very long custom field name' * 10, field_format: 'int') + assert field.invalid? + end + def test_default_value_should_be_validated field = CustomField.new(:name => 'Test', :field_format => 'int') field.default_value = 'abc' -- 2.25.1