summaryrefslogtreecommitdiffstats
path: root/test/unit/custom_value_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-01-24 18:15:38 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-01-24 18:15:38 +0000
commite13f49d91951a82d9989c2a0f0c4981832f2664f (patch)
treed302dde43b241690a16e03cd0d39dad71145fc53 /test/unit/custom_value_test.rb
parent7a1e928b8db0cc0a584011973042522cd7b38d4d (diff)
downloadredmine-e13f49d91951a82d9989c2a0f0c4981832f2664f.tar.gz
redmine-e13f49d91951a82d9989c2a0f0c4981832f2664f.zip
Prevent unexpected nil in custom value validation.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1101 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/custom_value_test.rb')
-rw-r--r--test/unit/custom_value_test.rb74
1 files changed, 73 insertions, 1 deletions
diff --git a/test/unit/custom_value_test.rb b/test/unit/custom_value_test.rb
index 4d488bae2..11578ae6b 100644
--- a/test/unit/custom_value_test.rb
+++ b/test/unit/custom_value_test.rb
@@ -20,7 +20,79 @@ require File.dirname(__FILE__) + '/../test_helper'
class CustomValueTest < Test::Unit::TestCase
fixtures :custom_fields
- def test_float_field
+ def test_string_field_validation_with_blank_value
+ f = CustomField.new(:field_format => 'string')
+ v = CustomValue.new(:custom_field => f)
+
+ v.value = nil
+ assert v.valid?
+ v.value = ''
+ assert v.valid?
+
+ f.is_required = true
+ v.value = nil
+ assert !v.valid?
+ v.value = ''
+ assert !v.valid?
+ end
+
+ def test_string_field_validation_with_min_and_max_lengths
+ f = CustomField.new(:field_format => 'string', :min_length => 2, :max_length => 5)
+ v = CustomValue.new(:custom_field => f, :value => '')
+ assert v.valid?
+ v.value = 'a'
+ assert !v.valid?
+ v.value = 'a' * 2
+ assert v.valid?
+ v.value = 'a' * 6
+ assert !v.valid?
+ end
+
+ def test_string_field_validation_with_regexp
+ f = CustomField.new(:field_format => 'string', :regexp => '^[A-Z0-9]*$')
+ v = CustomValue.new(:custom_field => f, :value => '')
+ assert v.valid?
+ v.value = 'abc'
+ assert !v.valid?
+ v.value = 'ABC'
+ assert v.valid?
+ end
+
+ def test_date_field_validation
+ f = CustomField.new(:field_format => 'date')
+ v = CustomValue.new(:custom_field => f, :value => '')
+ assert v.valid?
+ v.value = 'abc'
+ assert !v.valid?
+ v.value = '1975-07-14'
+ assert v.valid?
+ end
+
+ def test_list_field_validation
+ f = CustomField.new(:field_format => 'list', :possible_values => ['value1', 'value2'])
+ v = CustomValue.new(:custom_field => f, :value => '')
+ assert v.valid?
+ v.value = 'abc'
+ assert !v.valid?
+ v.value = 'value2'
+ assert v.valid?
+ end
+
+ def test_int_field_validation
+ f = CustomField.new(:field_format => 'int')
+ v = CustomValue.new(:custom_field => f, :value => '')
+ assert v.valid?
+ v.value = 'abc'
+ assert !v.valid?
+ v.value = '123'
+ assert v.valid?
+ v.value = '+123'
+ assert v.valid?
+ v.value = '-123'
+ assert v.valid?
+ end
+
+ def test_float_field_validation
v = CustomValue.new(:customized => User.find(:first), :custom_field => UserCustomField.find_by_name('Money'))
v.value = '11.2'
assert v.save