From: Jean-Philippe Lang Date: Sat, 14 Dec 2013 10:01:45 +0000 (+0000) Subject: Removed default values on custom field min and max length. X-Git-Tag: 2.5.0~477 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e715c4b847a8c9557dce49400e0dd309e19f7e82;p=redmine.git Removed default values on custom field min and max length. git-svn-id: http://svn.redmine.org/redmine/trunk@12405 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/views/custom_fields/formats/_regexp.html.erb b/app/views/custom_fields/formats/_regexp.html.erb index 0b630347a..9630d5a30 100644 --- a/app/views/custom_fields/formats/_regexp.html.erb +++ b/app/views/custom_fields/formats/_regexp.html.erb @@ -2,7 +2,6 @@ <%= f.text_field :min_length, :size => 5, :no_label => true %> - <%= f.text_field :max_length, :size => 5, :no_label => true %> - <%= l(:text_min_max_length_info) %>

<%= f.text_field :regexp, :size => 50 %> diff --git a/app/views/custom_fields/index.api.rsb b/app/views/custom_fields/index.api.rsb index 4dbd44c7a..902edff16 100644 --- a/app/views/custom_fields/index.api.rsb +++ b/app/views/custom_fields/index.api.rsb @@ -6,8 +6,8 @@ api.array :custom_fields do api.customized_type field.class.customized_class.name.underscore if field.class.customized_class api.field_format field.field_format api.regexp field.regexp - api.min_length (field.min_length == 0 ? nil : field.min_length) - api.max_length (field.max_length == 0 ? nil : field.max_length) + api.min_length field.min_length + api.max_length field.max_length api.is_required field.is_required? api.is_filter field.is_filter? api.searchable field.searchable diff --git a/db/migrate/20131214094309_remove_custom_fields_min_max_length_default_values.rb b/db/migrate/20131214094309_remove_custom_fields_min_max_length_default_values.rb new file mode 100644 index 000000000..d7111c12d --- /dev/null +++ b/db/migrate/20131214094309_remove_custom_fields_min_max_length_default_values.rb @@ -0,0 +1,15 @@ +class RemoveCustomFieldsMinMaxLengthDefaultValues < ActiveRecord::Migration + def up + change_column :custom_fields, :min_length, :int, :default => nil, :null => true + change_column :custom_fields, :max_length, :int, :default => nil, :null => true + CustomField.where(:min_length => 0).update_all(:min_length => nil) + CustomField.where(:max_length => 0).update_all(:max_length => nil) + end + + def self.down + CustomField.where(:min_length => nil).update_all(:min_length => 0) + CustomField.where(:max_length => nil).update_all(:max_length => 0) + change_column :custom_fields, :min_length, :int, :default => 0, :null => false + change_column :custom_fields, :max_length, :int, :default => 0, :null => false + end +end diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb index 399f7d150..ac27831be 100644 --- a/lib/redmine/field_format.rb +++ b/lib/redmine/field_format.rb @@ -218,10 +218,10 @@ module Redmine unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp) errs << ::I18n.t('activerecord.errors.messages.invalid') end - if custom_field.min_length > 0 and value.length < custom_field.min_length + if custom_field.min_length && value.length < custom_field.min_length errs << ::I18n.t('activerecord.errors.messages.too_short', :count => custom_field.min_length) end - if custom_field.max_length > 0 and value.length > custom_field.max_length + if custom_field.max_length && custom_field.max_length > 0 && value.length > custom_field.max_length errs << ::I18n.t('activerecord.errors.messages.too_long', :count => custom_field.max_length) end end diff --git a/test/fixtures/custom_fields.yml b/test/fixtures/custom_fields.yml index 976c19c26..510e3a41c 100644 --- a/test/fixtures/custom_fields.yml +++ b/test/fixtures/custom_fields.yml @@ -1,12 +1,10 @@ --- custom_fields_001: name: Database - min_length: 0 regexp: "" is_for_all: true is_filter: true type: IssueCustomField - max_length: 0 possible_values: - MySQL - PostgreSQL @@ -35,12 +33,10 @@ custom_fields_002: position: 1 custom_fields_003: name: Development status - min_length: 0 regexp: "" is_for_all: false is_filter: true type: ProjectCustomField - max_length: 0 possible_values: - Stable - Beta @@ -54,11 +50,9 @@ custom_fields_003: position: 1 custom_fields_004: name: Phone number - min_length: 0 regexp: "" is_for_all: false type: UserCustomField - max_length: 0 possible_values: "" id: 4 is_required: false @@ -68,11 +62,9 @@ custom_fields_004: position: 1 custom_fields_005: name: Money - min_length: 0 regexp: "" is_for_all: false type: UserCustomField - max_length: 0 possible_values: "" id: 5 is_required: false @@ -82,11 +74,9 @@ custom_fields_005: position: 2 custom_fields_006: name: Float field - min_length: 0 regexp: "" is_for_all: true type: IssueCustomField - max_length: 0 possible_values: "" id: 6 is_required: false @@ -96,12 +86,10 @@ custom_fields_006: position: 3 custom_fields_007: name: Billable - min_length: 0 regexp: "" is_for_all: false is_filter: true type: TimeEntryActivityCustomField - max_length: 0 possible_values: "" id: 7 is_required: false @@ -111,12 +99,10 @@ custom_fields_007: position: 1 custom_fields_008: name: Custom date - min_length: 0 regexp: "" is_for_all: true is_filter: false type: IssueCustomField - max_length: 0 possible_values: "" id: 8 is_required: false @@ -126,12 +112,10 @@ custom_fields_008: position: 4 custom_fields_009: name: Project 1 cf - min_length: 0 regexp: "" is_for_all: false is_filter: true type: IssueCustomField - max_length: 0 possible_values: "" id: 9 is_required: false @@ -141,12 +125,10 @@ custom_fields_009: position: 5 custom_fields_010: name: Overtime - min_length: 0 regexp: "" is_for_all: false is_filter: false type: TimeEntryCustomField - max_length: 0 possible_values: "" id: 10 is_required: false