@@ -1,78 +1,88 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 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 CustomFieldTest < ActiveSupport::TestCase |
|
20 | class CustomFieldTest < ActiveSupport::TestCase | |
21 | fixtures :custom_fields |
|
21 | fixtures :custom_fields | |
22 |
|
22 | |||
23 | def test_create |
|
23 | def test_create | |
24 | field = UserCustomField.new(:name => 'Money money money', :field_format => 'float') |
|
24 | field = UserCustomField.new(:name => 'Money money money', :field_format => 'float') | |
25 | assert field.save |
|
25 | assert field.save | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
|
28 | def test_before_validation | |||
|
29 | field = CustomField.new(:name => 'test_before_validation', :field_format => 'int') | |||
|
30 | field.searchable = true | |||
|
31 | assert field.save | |||
|
32 | assert_equal false, field.searchable | |||
|
33 | field.searchable = true | |||
|
34 | assert field.save | |||
|
35 | assert_equal false, field.searchable | |||
|
36 | end | |||
|
37 | ||||
28 | def test_regexp_validation |
|
38 | def test_regexp_validation | |
29 | field = IssueCustomField.new(:name => 'regexp', :field_format => 'text', :regexp => '[a-z0-9') |
|
39 | field = IssueCustomField.new(:name => 'regexp', :field_format => 'text', :regexp => '[a-z0-9') | |
30 | assert !field.save |
|
40 | assert !field.save | |
31 | assert_equal I18n.t('activerecord.errors.messages.invalid'), |
|
41 | assert_equal I18n.t('activerecord.errors.messages.invalid'), | |
32 | field.errors[:regexp].to_s |
|
42 | field.errors[:regexp].to_s | |
33 | field.regexp = '[a-z0-9]' |
|
43 | field.regexp = '[a-z0-9]' | |
34 | assert field.save |
|
44 | assert field.save | |
35 | end |
|
45 | end | |
36 |
|
46 | |||
37 | def test_possible_values_should_accept_an_array |
|
47 | def test_possible_values_should_accept_an_array | |
38 | field = CustomField.new |
|
48 | field = CustomField.new | |
39 | field.possible_values = ["One value", ""] |
|
49 | field.possible_values = ["One value", ""] | |
40 | assert_equal ["One value"], field.possible_values |
|
50 | assert_equal ["One value"], field.possible_values | |
41 | end |
|
51 | end | |
42 |
|
52 | |||
43 | def test_possible_values_should_accept_a_string |
|
53 | def test_possible_values_should_accept_a_string | |
44 | field = CustomField.new |
|
54 | field = CustomField.new | |
45 | field.possible_values = "One value" |
|
55 | field.possible_values = "One value" | |
46 | assert_equal ["One value"], field.possible_values |
|
56 | assert_equal ["One value"], field.possible_values | |
47 | end |
|
57 | end | |
48 |
|
58 | |||
49 | def test_possible_values_should_accept_a_multiline_string |
|
59 | def test_possible_values_should_accept_a_multiline_string | |
50 | field = CustomField.new |
|
60 | field = CustomField.new | |
51 | field.possible_values = "One value\nAnd another one \r\n \n" |
|
61 | field.possible_values = "One value\nAnd another one \r\n \n" | |
52 | assert_equal ["One value", "And another one"], field.possible_values |
|
62 | assert_equal ["One value", "And another one"], field.possible_values | |
53 | end |
|
63 | end | |
54 |
|
64 | |||
55 | def test_destroy |
|
65 | def test_destroy | |
56 | field = CustomField.find(1) |
|
66 | field = CustomField.find(1) | |
57 | assert field.destroy |
|
67 | assert field.destroy | |
58 | end |
|
68 | end | |
59 |
|
69 | |||
60 | def test_new_subclass_instance_should_return_an_instance |
|
70 | def test_new_subclass_instance_should_return_an_instance | |
61 | f = CustomField.new_subclass_instance('IssueCustomField') |
|
71 | f = CustomField.new_subclass_instance('IssueCustomField') | |
62 | assert_kind_of IssueCustomField, f |
|
72 | assert_kind_of IssueCustomField, f | |
63 | end |
|
73 | end | |
64 |
|
74 | |||
65 | def test_new_subclass_instance_should_set_attributes |
|
75 | def test_new_subclass_instance_should_set_attributes | |
66 | f = CustomField.new_subclass_instance('IssueCustomField', :name => 'Test') |
|
76 | f = CustomField.new_subclass_instance('IssueCustomField', :name => 'Test') | |
67 | assert_kind_of IssueCustomField, f |
|
77 | assert_kind_of IssueCustomField, f | |
68 | assert_equal 'Test', f.name |
|
78 | assert_equal 'Test', f.name | |
69 | end |
|
79 | end | |
70 |
|
80 | |||
71 | def test_new_subclass_instance_with_invalid_class_name_should_return_nil |
|
81 | def test_new_subclass_instance_with_invalid_class_name_should_return_nil | |
72 | assert_nil CustomField.new_subclass_instance('WrongClassName') |
|
82 | assert_nil CustomField.new_subclass_instance('WrongClassName') | |
73 | end |
|
83 | end | |
74 |
|
84 | |||
75 | def test_new_subclass_instance_with_non_subclass_name_should_return_nil |
|
85 | def test_new_subclass_instance_with_non_subclass_name_should_return_nil | |
76 | assert_nil CustomField.new_subclass_instance('Project') |
|
86 | assert_nil CustomField.new_subclass_instance('Project') | |
77 | end |
|
87 | end | |
78 | end |
|
88 | end |
General Comments 0
You need to be logged in to leave comments.
Login now