##// END OF EJS Templates
add missing fixtures to TimeEntryActivityTest...
Toshi MARUYAMA -
r13025:34beae1c7a78
parent child
Show More
@@ -1,116 +1,123
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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, :custom_fields
21 fixtures :enumerations, :time_entries, :custom_fields,
22 :issues, :projects, :users,
23 :members, :roles, :member_roles,
24 :trackers, :issue_statuses,
25 :projects_trackers,
26 :issue_categories,
27 :groups_users,
28 :enabled_modules
22
29
23 include Redmine::I18n
30 include Redmine::I18n
24
31
25 def test_should_be_an_enumeration
32 def test_should_be_an_enumeration
26 assert TimeEntryActivity.ancestors.include?(Enumeration)
33 assert TimeEntryActivity.ancestors.include?(Enumeration)
27 end
34 end
28
35
29 def test_objects_count
36 def test_objects_count
30 assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
37 assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
31 assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count
38 assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count
32 end
39 end
33
40
34 def test_option_name
41 def test_option_name
35 assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
42 assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
36 end
43 end
37
44
38 def test_create_with_custom_field
45 def test_create_with_custom_field
39 field = TimeEntryActivityCustomField.find_by_name('Billable')
46 field = TimeEntryActivityCustomField.find_by_name('Billable')
40 e = TimeEntryActivity.new(:name => 'Custom Data')
47 e = TimeEntryActivity.new(:name => 'Custom Data')
41 e.custom_field_values = {field.id => "1"}
48 e.custom_field_values = {field.id => "1"}
42 assert e.save
49 assert e.save
43
50
44 e.reload
51 e.reload
45 assert_equal "1", e.custom_value_for(field).value
52 assert_equal "1", e.custom_value_for(field).value
46 end
53 end
47
54
48 def test_create_without_required_custom_field_should_fail
55 def test_create_without_required_custom_field_should_fail
49 set_language_if_valid 'en'
56 set_language_if_valid 'en'
50 field = TimeEntryActivityCustomField.find_by_name('Billable')
57 field = TimeEntryActivityCustomField.find_by_name('Billable')
51 field.update_attribute(:is_required, true)
58 field.update_attribute(:is_required, true)
52
59
53 e = TimeEntryActivity.new(:name => 'Custom Data')
60 e = TimeEntryActivity.new(:name => 'Custom Data')
54 assert !e.save
61 assert !e.save
55 assert_equal ["Billable can't be blank"], e.errors.full_messages
62 assert_equal ["Billable can't be blank"], e.errors.full_messages
56 end
63 end
57
64
58 def test_create_with_required_custom_field_should_succeed
65 def test_create_with_required_custom_field_should_succeed
59 field = TimeEntryActivityCustomField.find_by_name('Billable')
66 field = TimeEntryActivityCustomField.find_by_name('Billable')
60 field.update_attribute(:is_required, true)
67 field.update_attribute(:is_required, true)
61
68
62 e = TimeEntryActivity.new(:name => 'Custom Data')
69 e = TimeEntryActivity.new(:name => 'Custom Data')
63 e.custom_field_values = {field.id => "1"}
70 e.custom_field_values = {field.id => "1"}
64 assert e.save
71 assert e.save
65 end
72 end
66
73
67 def test_update_with_required_custom_field_change
74 def test_update_with_required_custom_field_change
68 set_language_if_valid 'en'
75 set_language_if_valid 'en'
69 field = TimeEntryActivityCustomField.find_by_name('Billable')
76 field = TimeEntryActivityCustomField.find_by_name('Billable')
70 field.update_attribute(:is_required, true)
77 field.update_attribute(:is_required, true)
71
78
72 e = TimeEntryActivity.find(10)
79 e = TimeEntryActivity.find(10)
73 assert e.available_custom_fields.include?(field)
80 assert e.available_custom_fields.include?(field)
74 # No change to custom field, record can be saved
81 # No change to custom field, record can be saved
75 assert e.save
82 assert e.save
76 # Blanking custom field, save should fail
83 # Blanking custom field, save should fail
77 e.custom_field_values = {field.id => ""}
84 e.custom_field_values = {field.id => ""}
78 assert !e.save
85 assert !e.save
79 assert_equal ["Billable can't be blank"], e.errors.full_messages
86 assert_equal ["Billable can't be blank"], e.errors.full_messages
80
87
81 # Update custom field to valid value, save should succeed
88 # Update custom field to valid value, save should succeed
82 e.custom_field_values = {field.id => "0"}
89 e.custom_field_values = {field.id => "0"}
83 assert e.save
90 assert e.save
84 e.reload
91 e.reload
85 assert_equal "0", e.custom_value_for(field).value
92 assert_equal "0", e.custom_value_for(field).value
86 end
93 end
87
94
88 def test_system_activity_with_child_in_use_should_be_in_use
95 def test_system_activity_with_child_in_use_should_be_in_use
89 project = Project.generate!
96 project = Project.generate!
90 system_activity = TimeEntryActivity.create!(:name => 'Activity')
97 system_activity = TimeEntryActivity.create!(:name => 'Activity')
91 project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
98 project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
92
99
93 TimeEntry.generate!(:project => project, :activity => project_activity)
100 TimeEntry.generate!(:project => project, :activity => project_activity)
94
101
95 assert project_activity.in_use?
102 assert project_activity.in_use?
96 assert system_activity.in_use?
103 assert system_activity.in_use?
97 end
104 end
98
105
99 def test_destroying_a_system_activity_should_reassign_children_activities
106 def test_destroying_a_system_activity_should_reassign_children_activities
100 project = Project.generate!
107 project = Project.generate!
101 system_activity = TimeEntryActivity.create!(:name => 'Activity')
108 system_activity = TimeEntryActivity.create!(:name => 'Activity')
102 project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
109 project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
103
110
104 entries = [
111 entries = [
105 TimeEntry.generate!(:project => project, :activity => system_activity),
112 TimeEntry.generate!(:project => project, :activity => system_activity),
106 TimeEntry.generate!(:project => project, :activity => project_activity)
113 TimeEntry.generate!(:project => project, :activity => project_activity)
107 ]
114 ]
108
115
109 assert_difference 'TimeEntryActivity.count', -2 do
116 assert_difference 'TimeEntryActivity.count', -2 do
110 assert_nothing_raised do
117 assert_nothing_raised do
111 assert system_activity.destroy(TimeEntryActivity.find_by_name('Development'))
118 assert system_activity.destroy(TimeEntryActivity.find_by_name('Development'))
112 end
119 end
113 end
120 end
114 assert entries.all? {|entry| entry.reload.activity.name == 'Development'}
121 assert entries.all? {|entry| entry.reload.activity.name == 'Development'}
115 end
122 end
116 end
123 end
General Comments 0
You need to be logged in to leave comments. Login now