# 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
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)
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
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')
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
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')
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')
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')