@@ -1,88 +1,88 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 TimeEntryActivityTest < ActiveSupport::TestCase |
|
20 | class TimeEntryActivityTest < ActiveSupport::TestCase | |
21 | fixtures :enumerations, :time_entries |
|
21 | fixtures :enumerations, :time_entries | |
22 |
|
22 | |||
23 | include Redmine::I18n |
|
23 | include Redmine::I18n | |
24 |
|
24 | |||
25 | def test_should_be_an_enumeration |
|
25 | def test_should_be_an_enumeration | |
26 | assert TimeEntryActivity.ancestors.include?(Enumeration) |
|
26 | assert TimeEntryActivity.ancestors.include?(Enumeration) | |
27 | end |
|
27 | end | |
28 |
|
28 | |||
29 | def test_objects_count |
|
29 | def test_objects_count | |
30 | assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count |
|
30 | assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count | |
31 | assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count |
|
31 | assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_option_name |
|
34 | def test_option_name | |
35 | assert_equal :enumeration_activities, TimeEntryActivity.new.option_name |
|
35 | assert_equal :enumeration_activities, TimeEntryActivity.new.option_name | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def test_create_with_custom_field |
|
38 | def test_create_with_custom_field | |
39 | field = TimeEntryActivityCustomField.find_by_name('Billable') |
|
39 | field = TimeEntryActivityCustomField.find_by_name('Billable') | |
40 | e = TimeEntryActivity.new(:name => 'Custom Data') |
|
40 | e = TimeEntryActivity.new(:name => 'Custom Data') | |
41 | e.custom_field_values = {field.id => "1"} |
|
41 | e.custom_field_values = {field.id => "1"} | |
42 | assert e.save |
|
42 | assert e.save | |
43 |
|
43 | |||
44 | e.reload |
|
44 | e.reload | |
45 | assert_equal "1", e.custom_value_for(field).value |
|
45 | assert_equal "1", e.custom_value_for(field).value | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_create_without_required_custom_field_should_fail |
|
48 | def test_create_without_required_custom_field_should_fail | |
49 | set_language_if_valid 'en' |
|
49 | set_language_if_valid 'en' | |
50 | field = TimeEntryActivityCustomField.find_by_name('Billable') |
|
50 | field = TimeEntryActivityCustomField.find_by_name('Billable') | |
51 | field.update_attribute(:is_required, true) |
|
51 | field.update_attribute(:is_required, true) | |
52 |
|
52 | |||
53 | e = TimeEntryActivity.new(:name => 'Custom Data') |
|
53 | e = TimeEntryActivity.new(:name => 'Custom Data') | |
54 | assert !e.save |
|
54 | assert !e.save | |
55 |
assert_equal "Billable can't be blank", e.errors |
|
55 | assert_equal ["Billable can't be blank"], e.errors.full_messages | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | def test_create_with_required_custom_field_should_succeed |
|
58 | def test_create_with_required_custom_field_should_succeed | |
59 | field = TimeEntryActivityCustomField.find_by_name('Billable') |
|
59 | field = TimeEntryActivityCustomField.find_by_name('Billable') | |
60 | field.update_attribute(:is_required, true) |
|
60 | field.update_attribute(:is_required, true) | |
61 |
|
61 | |||
62 | e = TimeEntryActivity.new(:name => 'Custom Data') |
|
62 | e = TimeEntryActivity.new(:name => 'Custom Data') | |
63 | e.custom_field_values = {field.id => "1"} |
|
63 | e.custom_field_values = {field.id => "1"} | |
64 | assert e.save |
|
64 | assert e.save | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def test_update_with_required_custom_field_change |
|
67 | def test_update_with_required_custom_field_change | |
68 | set_language_if_valid 'en' |
|
68 | set_language_if_valid 'en' | |
69 | field = TimeEntryActivityCustomField.find_by_name('Billable') |
|
69 | field = TimeEntryActivityCustomField.find_by_name('Billable') | |
70 | field.update_attribute(:is_required, true) |
|
70 | field.update_attribute(:is_required, true) | |
71 |
|
71 | |||
72 | e = TimeEntryActivity.find(10) |
|
72 | e = TimeEntryActivity.find(10) | |
73 | assert e.available_custom_fields.include?(field) |
|
73 | assert e.available_custom_fields.include?(field) | |
74 | # No change to custom field, record can be saved |
|
74 | # No change to custom field, record can be saved | |
75 | assert e.save |
|
75 | assert e.save | |
76 | # Blanking custom field, save should fail |
|
76 | # Blanking custom field, save should fail | |
77 | e.custom_field_values = {field.id => ""} |
|
77 | e.custom_field_values = {field.id => ""} | |
78 | assert !e.save |
|
78 | assert !e.save | |
79 |
assert_equal "Billable can't be blank", e.errors |
|
79 | assert_equal ["Billable can't be blank"], e.errors.full_messages | |
80 |
|
80 | |||
81 | # Update custom field to valid value, save should succeed |
|
81 | # Update custom field to valid value, save should succeed | |
82 | e.custom_field_values = {field.id => "0"} |
|
82 | e.custom_field_values = {field.id => "0"} | |
83 | assert e.save |
|
83 | assert e.save | |
84 | e.reload |
|
84 | e.reload | |
85 | assert_equal "0", e.custom_value_for(field).value |
|
85 | assert_equal "0", e.custom_value_for(field).value | |
86 | end |
|
86 | end | |
87 | end |
|
87 | end | |
88 |
|
88 |
General Comments 0
You need to be logged in to leave comments.
Login now