Backported r12938 (#16169).

git-svn-id: http://svn.redmine.org/redmine/branches/2.4-stable@12940 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2014-02-28 11:40:02 +00:00
parent 8d7fd10f90
commit 40abbfa82d
2 changed files with 9 additions and 1 deletions

View File

@ -350,7 +350,7 @@ class CustomField < ActiveRecord::Base
# Returns the error message for the given value regarding its format
def validate_field_value_format(value)
errs = []
if value.present?
unless value.to_s == ''
errs << ::I18n.t('activerecord.errors.messages.invalid') unless regexp.blank? or value =~ Regexp.new(regexp)
errs << ::I18n.t('activerecord.errors.messages.too_short', :count => min_length) if min_length > 0 and value.length < min_length
errs << ::I18n.t('activerecord.errors.messages.too_long', :count => max_length) if max_length > 0 and value.length > max_length

View File

@ -146,6 +146,7 @@ class CustomFieldTest < ActiveSupport::TestCase
assert f.valid_field_value?(nil)
assert f.valid_field_value?('')
assert !f.valid_field_value?(' ')
assert f.valid_field_value?('a' * 2)
assert !f.valid_field_value?('a')
assert !f.valid_field_value?('a' * 6)
@ -156,6 +157,7 @@ class CustomFieldTest < ActiveSupport::TestCase
assert f.valid_field_value?(nil)
assert f.valid_field_value?('')
assert !f.valid_field_value?(' ')
assert f.valid_field_value?('ABC')
assert !f.valid_field_value?('abc')
end
@ -165,6 +167,7 @@ class CustomFieldTest < ActiveSupport::TestCase
assert f.valid_field_value?(nil)
assert f.valid_field_value?('')
assert !f.valid_field_value?(' ')
assert f.valid_field_value?('1975-07-14')
assert !f.valid_field_value?('1975-07-33')
assert !f.valid_field_value?('abc')
@ -175,6 +178,7 @@ class CustomFieldTest < ActiveSupport::TestCase
assert f.valid_field_value?(nil)
assert f.valid_field_value?('')
assert !f.valid_field_value?(' ')
assert f.valid_field_value?('value2')
assert !f.valid_field_value?('abc')
end
@ -184,6 +188,7 @@ class CustomFieldTest < ActiveSupport::TestCase
assert f.valid_field_value?(nil)
assert f.valid_field_value?('')
assert !f.valid_field_value?(' ')
assert f.valid_field_value?('123')
assert f.valid_field_value?('+123')
assert f.valid_field_value?('-123')
@ -195,6 +200,7 @@ class CustomFieldTest < ActiveSupport::TestCase
assert f.valid_field_value?(nil)
assert f.valid_field_value?('')
assert !f.valid_field_value?(' ')
assert f.valid_field_value?('11.2')
assert f.valid_field_value?('-6.250')
assert f.valid_field_value?('5')
@ -206,9 +212,11 @@ class CustomFieldTest < ActiveSupport::TestCase
assert f.valid_field_value?(nil)
assert f.valid_field_value?('')
assert !f.valid_field_value?(' ')
assert f.valid_field_value?([])
assert f.valid_field_value?([nil])
assert f.valid_field_value?([''])
assert !f.valid_field_value?([' '])
assert f.valid_field_value?('value2')
assert !f.valid_field_value?('abc')