##// END OF EJS Templates
remove trailing white-spaces from test/unit/custom_value_test.rb....
Toshi MARUYAMA -
r6604:c2d21ce2d3d7
parent child
Show More
@@ -1,123 +1,123
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class CustomValueTest < ActiveSupport::TestCase
20 class CustomValueTest < ActiveSupport::TestCase
21 fixtures :custom_fields, :custom_values, :users
21 fixtures :custom_fields, :custom_values, :users
22
22
23 def test_string_field_validation_with_blank_value
23 def test_string_field_validation_with_blank_value
24 f = CustomField.new(:field_format => 'string')
24 f = CustomField.new(:field_format => 'string')
25 v = CustomValue.new(:custom_field => f)
25 v = CustomValue.new(:custom_field => f)
26
26
27 v.value = nil
27 v.value = nil
28 assert v.valid?
28 assert v.valid?
29 v.value = ''
29 v.value = ''
30 assert v.valid?
30 assert v.valid?
31
31
32 f.is_required = true
32 f.is_required = true
33 v.value = nil
33 v.value = nil
34 assert !v.valid?
34 assert !v.valid?
35 v.value = ''
35 v.value = ''
36 assert !v.valid?
36 assert !v.valid?
37 end
37 end
38
38
39 def test_string_field_validation_with_min_and_max_lengths
39 def test_string_field_validation_with_min_and_max_lengths
40 f = CustomField.new(:field_format => 'string', :min_length => 2, :max_length => 5)
40 f = CustomField.new(:field_format => 'string', :min_length => 2, :max_length => 5)
41 v = CustomValue.new(:custom_field => f, :value => '')
41 v = CustomValue.new(:custom_field => f, :value => '')
42 assert v.valid?
42 assert v.valid?
43 v.value = 'a'
43 v.value = 'a'
44 assert !v.valid?
44 assert !v.valid?
45 v.value = 'a' * 2
45 v.value = 'a' * 2
46 assert v.valid?
46 assert v.valid?
47 v.value = 'a' * 6
47 v.value = 'a' * 6
48 assert !v.valid?
48 assert !v.valid?
49 end
49 end
50
50
51 def test_string_field_validation_with_regexp
51 def test_string_field_validation_with_regexp
52 f = CustomField.new(:field_format => 'string', :regexp => '^[A-Z0-9]*$')
52 f = CustomField.new(:field_format => 'string', :regexp => '^[A-Z0-9]*$')
53 v = CustomValue.new(:custom_field => f, :value => '')
53 v = CustomValue.new(:custom_field => f, :value => '')
54 assert v.valid?
54 assert v.valid?
55 v.value = 'abc'
55 v.value = 'abc'
56 assert !v.valid?
56 assert !v.valid?
57 v.value = 'ABC'
57 v.value = 'ABC'
58 assert v.valid?
58 assert v.valid?
59 end
59 end
60
60
61 def test_date_field_validation
61 def test_date_field_validation
62 f = CustomField.new(:field_format => 'date')
62 f = CustomField.new(:field_format => 'date')
63 v = CustomValue.new(:custom_field => f, :value => '')
63 v = CustomValue.new(:custom_field => f, :value => '')
64 assert v.valid?
64 assert v.valid?
65 v.value = 'abc'
65 v.value = 'abc'
66 assert !v.valid?
66 assert !v.valid?
67 v.value = '1975-07-14'
67 v.value = '1975-07-14'
68 assert v.valid?
68 assert v.valid?
69 end
69 end
70
70
71 def test_list_field_validation
71 def test_list_field_validation
72 f = CustomField.new(:field_format => 'list', :possible_values => ['value1', 'value2'])
72 f = CustomField.new(:field_format => 'list', :possible_values => ['value1', 'value2'])
73 v = CustomValue.new(:custom_field => f, :value => '')
73 v = CustomValue.new(:custom_field => f, :value => '')
74 assert v.valid?
74 assert v.valid?
75 v.value = 'abc'
75 v.value = 'abc'
76 assert !v.valid?
76 assert !v.valid?
77 v.value = 'value2'
77 v.value = 'value2'
78 assert v.valid?
78 assert v.valid?
79 end
79 end
80
80
81 def test_int_field_validation
81 def test_int_field_validation
82 f = CustomField.new(:field_format => 'int')
82 f = CustomField.new(:field_format => 'int')
83 v = CustomValue.new(:custom_field => f, :value => '')
83 v = CustomValue.new(:custom_field => f, :value => '')
84 assert v.valid?
84 assert v.valid?
85 v.value = 'abc'
85 v.value = 'abc'
86 assert !v.valid?
86 assert !v.valid?
87 v.value = '123'
87 v.value = '123'
88 assert v.valid?
88 assert v.valid?
89 v.value = '+123'
89 v.value = '+123'
90 assert v.valid?
90 assert v.valid?
91 v.value = '-123'
91 v.value = '-123'
92 assert v.valid?
92 assert v.valid?
93 end
93 end
94
94
95 def test_float_field_validation
95 def test_float_field_validation
96 v = CustomValue.new(:customized => User.find(:first), :custom_field => UserCustomField.find_by_name('Money'))
96 v = CustomValue.new(:customized => User.find(:first), :custom_field => UserCustomField.find_by_name('Money'))
97 v.value = '11.2'
97 v.value = '11.2'
98 assert v.save
98 assert v.save
99 v.value = ''
99 v.value = ''
100 assert v.save
100 assert v.save
101 v.value = '-6.250'
101 v.value = '-6.250'
102 assert v.save
102 assert v.save
103 v.value = '6a'
103 v.value = '6a'
104 assert !v.save
104 assert !v.save
105 end
105 end
106
106
107 def test_default_value
107 def test_default_value
108 field = CustomField.find_by_default_value('Default string')
108 field = CustomField.find_by_default_value('Default string')
109 assert_not_nil field
109 assert_not_nil field
110
110
111 v = CustomValue.new(:custom_field => field)
111 v = CustomValue.new(:custom_field => field)
112 assert_equal 'Default string', v.value
112 assert_equal 'Default string', v.value
113
113
114 v = CustomValue.new(:custom_field => field, :value => 'Not empty')
114 v = CustomValue.new(:custom_field => field, :value => 'Not empty')
115 assert_equal 'Not empty', v.value
115 assert_equal 'Not empty', v.value
116 end
116 end
117
117
118 def test_sti_polymorphic_association
118 def test_sti_polymorphic_association
119 # Rails uses top level sti class for polymorphic association. See #3978.
119 # Rails uses top level sti class for polymorphic association. See #3978.
120 assert !User.find(4).custom_values.empty?
120 assert !User.find(4).custom_values.empty?
121 assert !CustomValue.find(2).customized.nil?
121 assert !CustomValue.find(2).customized.nil?
122 end
122 end
123 end
123 end
General Comments 0
You need to be logged in to leave comments. Login now