@@ -1,234 +1,235 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 ProjectEnumerationsControllerTest < ActionController::TestCase |
|
20 | class ProjectEnumerationsControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
21 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
22 | :enumerations, :users, :issue_categories, |
|
22 | :enumerations, :users, :issue_categories, | |
23 | :projects_trackers, |
|
23 | :projects_trackers, | |
24 | :roles, |
|
24 | :roles, | |
25 | :member_roles, |
|
25 | :member_roles, | |
26 | :members, |
|
26 | :members, | |
27 | :enabled_modules, |
|
27 | :enabled_modules, | |
28 | :custom_fields, :custom_fields_projects, |
|
28 | :custom_fields, :custom_fields_projects, | |
29 | :custom_fields_trackers, :custom_values, |
|
29 | :custom_fields_trackers, :custom_values, | |
30 | :time_entries |
|
30 | :time_entries | |
31 |
|
31 | |||
32 | self.use_transactional_fixtures = false |
|
32 | self.use_transactional_fixtures = false | |
33 |
|
33 | |||
34 | def setup |
|
34 | def setup | |
35 | @request.session[:user_id] = nil |
|
35 | @request.session[:user_id] = nil | |
36 | Setting.default_language = 'en' |
|
36 | Setting.default_language = 'en' | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | def test_update_to_override_system_activities |
|
39 | def test_update_to_override_system_activities | |
40 | @request.session[:user_id] = 2 # manager |
|
40 | @request.session[:user_id] = 2 # manager | |
41 | billable_field = TimeEntryActivityCustomField.find_by_name("Billable") |
|
41 | billable_field = TimeEntryActivityCustomField.find_by_name("Billable") | |
42 |
|
42 | |||
43 | put :update, :project_id => 1, :enumerations => { |
|
43 | put :update, :project_id => 1, :enumerations => { | |
44 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate |
|
44 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate | |
45 | "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value |
|
45 | "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value | |
46 | "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value |
|
46 | "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value | |
47 | "11"=>{"parent_id"=>"11", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"} # QA, no changes |
|
47 | "11"=>{"parent_id"=>"11", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"} # QA, no changes | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | assert_response :redirect |
|
50 | assert_response :redirect | |
51 | assert_redirected_to '/projects/ecookbook/settings/activities' |
|
51 | assert_redirected_to '/projects/ecookbook/settings/activities' | |
52 |
|
52 | |||
53 | # Created project specific activities... |
|
53 | # Created project specific activities... | |
54 | project = Project.find('ecookbook') |
|
54 | project = Project.find('ecookbook') | |
55 |
|
55 | |||
56 | # ... Design |
|
56 | # ... Design | |
57 | design = project.time_entry_activities.find_by_name("Design") |
|
57 | design = project.time_entry_activities.find_by_name("Design") | |
58 | assert design, "Project activity not found" |
|
58 | assert design, "Project activity not found" | |
59 |
|
59 | |||
60 | assert_equal 9, design.parent_id # Relate to the system activity |
|
60 | assert_equal 9, design.parent_id # Relate to the system activity | |
61 | assert_not_equal design.parent.id, design.id # Different records |
|
61 | assert_not_equal design.parent.id, design.id # Different records | |
62 | assert_equal design.parent.name, design.name # Same name |
|
62 | assert_equal design.parent.name, design.name # Same name | |
63 | assert !design.active? |
|
63 | assert !design.active? | |
64 |
|
64 | |||
65 | # ... Development |
|
65 | # ... Development | |
66 | development = project.time_entry_activities.find_by_name("Development") |
|
66 | development = project.time_entry_activities.find_by_name("Development") | |
67 | assert development, "Project activity not found" |
|
67 | assert development, "Project activity not found" | |
68 |
|
68 | |||
69 | assert_equal 10, development.parent_id # Relate to the system activity |
|
69 | assert_equal 10, development.parent_id # Relate to the system activity | |
70 | assert_not_equal development.parent.id, development.id # Different records |
|
70 | assert_not_equal development.parent.id, development.id # Different records | |
71 | assert_equal development.parent.name, development.name # Same name |
|
71 | assert_equal development.parent.name, development.name # Same name | |
72 | assert development.active? |
|
72 | assert development.active? | |
73 | assert_equal "0", development.custom_value_for(billable_field).value |
|
73 | assert_equal "0", development.custom_value_for(billable_field).value | |
74 |
|
74 | |||
75 | # ... Inactive Activity |
|
75 | # ... Inactive Activity | |
76 | previously_inactive = project.time_entry_activities.find_by_name("Inactive Activity") |
|
76 | previously_inactive = project.time_entry_activities.find_by_name("Inactive Activity") | |
77 | assert previously_inactive, "Project activity not found" |
|
77 | assert previously_inactive, "Project activity not found" | |
78 |
|
78 | |||
79 | assert_equal 14, previously_inactive.parent_id # Relate to the system activity |
|
79 | assert_equal 14, previously_inactive.parent_id # Relate to the system activity | |
80 | assert_not_equal previously_inactive.parent.id, previously_inactive.id # Different records |
|
80 | assert_not_equal previously_inactive.parent.id, previously_inactive.id # Different records | |
81 | assert_equal previously_inactive.parent.name, previously_inactive.name # Same name |
|
81 | assert_equal previously_inactive.parent.name, previously_inactive.name # Same name | |
82 | assert previously_inactive.active? |
|
82 | assert previously_inactive.active? | |
83 | assert_equal "1", previously_inactive.custom_value_for(billable_field).value |
|
83 | assert_equal "1", previously_inactive.custom_value_for(billable_field).value | |
84 |
|
84 | |||
85 | # ... QA |
|
85 | # ... QA | |
86 | assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified" |
|
86 | assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified" | |
87 | end |
|
87 | end | |
88 |
|
88 | |||
89 | def test_update_will_update_project_specific_activities |
|
89 | def test_update_will_update_project_specific_activities | |
90 | @request.session[:user_id] = 2 # manager |
|
90 | @request.session[:user_id] = 2 # manager | |
91 |
|
91 | |||
92 | project_activity = TimeEntryActivity.new({ |
|
92 | project_activity = TimeEntryActivity.new({ | |
93 | :name => 'Project Specific', |
|
93 | :name => 'Project Specific', | |
94 | :parent => TimeEntryActivity.first, |
|
94 | :parent => TimeEntryActivity.first, | |
95 | :project => Project.find(1), |
|
95 | :project => Project.find(1), | |
96 | :active => true |
|
96 | :active => true | |
97 | }) |
|
97 | }) | |
98 | assert project_activity.save |
|
98 | assert project_activity.save | |
99 | project_activity_two = TimeEntryActivity.new({ |
|
99 | project_activity_two = TimeEntryActivity.new({ | |
100 | :name => 'Project Specific Two', |
|
100 | :name => 'Project Specific Two', | |
101 | :parent => TimeEntryActivity.last, |
|
101 | :parent => TimeEntryActivity.last, | |
102 | :project => Project.find(1), |
|
102 | :project => Project.find(1), | |
103 | :active => true |
|
103 | :active => true | |
104 | }) |
|
104 | }) | |
105 | assert project_activity_two.save |
|
105 | assert project_activity_two.save | |
106 |
|
106 | |||
107 |
|
107 | |||
108 | put :update, :project_id => 1, :enumerations => { |
|
108 | put :update, :project_id => 1, :enumerations => { | |
109 | project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate |
|
109 | project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate | |
110 | project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate |
|
110 | project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | assert_response :redirect |
|
113 | assert_response :redirect | |
114 | assert_redirected_to '/projects/ecookbook/settings/activities' |
|
114 | assert_redirected_to '/projects/ecookbook/settings/activities' | |
115 |
|
115 | |||
116 | # Created project specific activities... |
|
116 | # Created project specific activities... | |
117 | project = Project.find('ecookbook') |
|
117 | project = Project.find('ecookbook') | |
118 | assert_equal 2, project.time_entry_activities.count |
|
118 | assert_equal 2, project.time_entry_activities.count | |
119 |
|
119 | |||
120 | activity_one = project.time_entry_activities.find_by_name(project_activity.name) |
|
120 | activity_one = project.time_entry_activities.find_by_name(project_activity.name) | |
121 | assert activity_one, "Project activity not found" |
|
121 | assert activity_one, "Project activity not found" | |
122 | assert_equal project_activity.id, activity_one.id |
|
122 | assert_equal project_activity.id, activity_one.id | |
123 | assert !activity_one.active? |
|
123 | assert !activity_one.active? | |
124 |
|
124 | |||
125 | activity_two = project.time_entry_activities.find_by_name(project_activity_two.name) |
|
125 | activity_two = project.time_entry_activities.find_by_name(project_activity_two.name) | |
126 | assert activity_two, "Project activity not found" |
|
126 | assert activity_two, "Project activity not found" | |
127 | assert_equal project_activity_two.id, activity_two.id |
|
127 | assert_equal project_activity_two.id, activity_two.id | |
128 | assert !activity_two.active? |
|
128 | assert !activity_two.active? | |
129 | end |
|
129 | end | |
130 |
|
130 | |||
131 | def test_update_when_creating_new_activities_will_convert_existing_data |
|
131 | def test_update_when_creating_new_activities_will_convert_existing_data | |
132 | assert_equal 3, TimeEntry.where(:activity_id => 9, :project_id => 1).count |
|
132 | assert_equal 3, TimeEntry.where(:activity_id => 9, :project_id => 1).count | |
133 |
|
133 | |||
134 | @request.session[:user_id] = 2 # manager |
|
134 | @request.session[:user_id] = 2 # manager | |
135 | put :update, :project_id => 1, :enumerations => { |
|
135 | put :update, :project_id => 1, :enumerations => { | |
136 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate |
|
136 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate | |
137 | } |
|
137 | } | |
138 | assert_response :redirect |
|
138 | assert_response :redirect | |
139 |
|
139 | |||
140 | # No more TimeEntries using the system activity |
|
140 | # No more TimeEntries using the system activity | |
141 | assert_equal 0, TimeEntry.where(:activity_id => 9, :project_id => 1).count, |
|
141 | assert_equal 0, TimeEntry.where(:activity_id => 9, :project_id => 1).count, | |
142 | "Time Entries still assigned to system activities" |
|
142 | "Time Entries still assigned to system activities" | |
143 | # All TimeEntries using project activity |
|
143 | # All TimeEntries using project activity | |
144 | project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1) |
|
144 | project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1) | |
145 | assert_equal 3, TimeEntry.where(:activity_id => project_specific_activity.id, |
|
145 | assert_equal 3, TimeEntry.where(:activity_id => project_specific_activity.id, | |
146 | :project_id => 1).count |
|
146 | :project_id => 1).count | |
147 | "No Time Entries assigned to the project activity" |
|
147 | "No Time Entries assigned to the project activity" | |
148 | end |
|
148 | end | |
149 |
|
149 | |||
150 | def test_update_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised |
|
150 | def test_update_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised | |
151 | # TODO: Need to cause an exception on create but these tests |
|
151 | # TODO: Need to cause an exception on create but these tests | |
152 | # aren't setup for mocking. Just create a record now so the |
|
152 | # aren't setup for mocking. Just create a record now so the | |
153 | # second one is a dupicate |
|
153 | # second one is a dupicate | |
154 | parent = TimeEntryActivity.find(9) |
|
154 | parent = TimeEntryActivity.find(9) | |
155 | TimeEntryActivity.create!({:name => parent.name, :project_id => 1, |
|
155 | TimeEntryActivity.create!({:name => parent.name, :project_id => 1, | |
156 | :position => parent.position, :active => true}) |
|
156 | :position => parent.position, :active => true}) | |
157 | TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), |
|
157 | TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), | |
158 | :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'}) |
|
158 | :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'}) | |
159 | assert_equal 3, TimeEntry.where(:activity_id => 9, :project_id => 1).count |
|
159 | assert_equal 3, TimeEntry.where(:activity_id => 9, :project_id => 1).count | |
160 | assert_equal 1, TimeEntry.where(:activity_id => 10, :project_id => 1).count |
|
160 | assert_equal 1, TimeEntry.where(:activity_id => 10, :project_id => 1).count | |
161 |
|
161 | |||
162 | @request.session[:user_id] = 2 # manager |
|
162 | @request.session[:user_id] = 2 # manager | |
163 | put :update, :project_id => 1, :enumerations => { |
|
163 | put :update, :project_id => 1, :enumerations => { | |
164 | # Design |
|
164 | # Design | |
165 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, |
|
165 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, | |
166 | # Development, Change custom value |
|
166 | # Development, Change custom value | |
167 | "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} |
|
167 | "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} | |
168 | } |
|
168 | } | |
169 | assert_response :redirect |
|
169 | assert_response :redirect | |
170 |
|
170 | |||
171 | # TimeEntries shouldn't have been reassigned on the failed record |
|
171 | # TimeEntries shouldn't have been reassigned on the failed record | |
172 | assert_equal 3, TimeEntry.where(:activity_id => 9, |
|
172 | assert_equal 3, TimeEntry.where(:activity_id => 9, | |
173 | :project_id => 1).count |
|
173 | :project_id => 1).count | |
174 | "Time Entries are not assigned to system activities" |
|
174 | "Time Entries are not assigned to system activities" | |
175 | # TimeEntries shouldn't have been reassigned on the saved record either |
|
175 | # TimeEntries shouldn't have been reassigned on the saved record either | |
176 | assert_equal 1, TimeEntry.where(:activity_id => 10, |
|
176 | assert_equal 1, TimeEntry.where(:activity_id => 10, | |
177 | :project_id => 1).count |
|
177 | :project_id => 1).count | |
178 | "Time Entries are not assigned to system activities" |
|
178 | "Time Entries are not assigned to system activities" | |
179 | end |
|
179 | end | |
180 |
|
180 | |||
181 | def test_destroy |
|
181 | def test_destroy | |
182 | @request.session[:user_id] = 2 # manager |
|
182 | @request.session[:user_id] = 2 # manager | |
183 | project_activity = TimeEntryActivity.new({ |
|
183 | project_activity = TimeEntryActivity.new({ | |
184 | :name => 'Project Specific', |
|
184 | :name => 'Project Specific', | |
185 | :parent => TimeEntryActivity.first, |
|
185 | :parent => TimeEntryActivity.first, | |
186 | :project => Project.find(1), |
|
186 | :project => Project.find(1), | |
187 | :active => true |
|
187 | :active => true | |
188 | }) |
|
188 | }) | |
189 | assert project_activity.save |
|
189 | assert project_activity.save | |
190 | project_activity_two = TimeEntryActivity.new({ |
|
190 | project_activity_two = TimeEntryActivity.new({ | |
191 | :name => 'Project Specific Two', |
|
191 | :name => 'Project Specific Two', | |
192 | :parent => TimeEntryActivity.last, |
|
192 | :parent => TimeEntryActivity.last, | |
193 | :project => Project.find(1), |
|
193 | :project => Project.find(1), | |
194 | :active => true |
|
194 | :active => true | |
195 | }) |
|
195 | }) | |
196 | assert project_activity_two.save |
|
196 | assert project_activity_two.save | |
197 |
|
197 | |||
198 | delete :destroy, :project_id => 1 |
|
198 | delete :destroy, :project_id => 1 | |
199 | assert_response :redirect |
|
199 | assert_response :redirect | |
200 | assert_redirected_to '/projects/ecookbook/settings/activities' |
|
200 | assert_redirected_to '/projects/ecookbook/settings/activities' | |
201 |
|
201 | |||
202 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) |
|
202 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) | |
203 | assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) |
|
203 | assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) | |
204 | end |
|
204 | end | |
205 |
|
205 | |||
206 | def test_destroy_should_reassign_time_entries_back_to_the_system_activity |
|
206 | def test_destroy_should_reassign_time_entries_back_to_the_system_activity | |
207 | @request.session[:user_id] = 2 # manager |
|
207 | @request.session[:user_id] = 2 # manager | |
208 | project_activity = TimeEntryActivity.new({ |
|
208 | project_activity = TimeEntryActivity.new({ | |
209 | :name => 'Project Specific Design', |
|
209 | :name => 'Project Specific Design', | |
210 | :parent => TimeEntryActivity.find(9), |
|
210 | :parent => TimeEntryActivity.find(9), | |
211 | :project => Project.find(1), |
|
211 | :project => Project.find(1), | |
212 | :active => true |
|
212 | :active => true | |
213 | }) |
|
213 | }) | |
214 | assert project_activity.save |
|
214 | assert project_activity.save | |
215 |
assert TimeEntry. |
|
215 | assert TimeEntry.where(["project_id = ? AND activity_id = ?", 1, 9]). | |
|
216 | update_all("activity_id = '#{project_activity.id}'") | |||
216 | assert_equal 3, TimeEntry.where(:activity_id => project_activity.id, |
|
217 | assert_equal 3, TimeEntry.where(:activity_id => project_activity.id, | |
217 | :project_id => 1).count |
|
218 | :project_id => 1).count | |
218 | delete :destroy, :project_id => 1 |
|
219 | delete :destroy, :project_id => 1 | |
219 | assert_response :redirect |
|
220 | assert_response :redirect | |
220 | assert_redirected_to '/projects/ecookbook/settings/activities' |
|
221 | assert_redirected_to '/projects/ecookbook/settings/activities' | |
221 |
|
222 | |||
222 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) |
|
223 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) | |
223 | assert_equal 0, TimeEntry.where( |
|
224 | assert_equal 0, TimeEntry.where( | |
224 | :activity_id => project_activity.id, |
|
225 | :activity_id => project_activity.id, | |
225 | :project_id => 1 |
|
226 | :project_id => 1 | |
226 | ).count, |
|
227 | ).count, | |
227 | "TimeEntries still assigned to project specific activity" |
|
228 | "TimeEntries still assigned to project specific activity" | |
228 | assert_equal 3, TimeEntry.where( |
|
229 | assert_equal 3, TimeEntry.where( | |
229 | :activity_id => 9, |
|
230 | :activity_id => 9, | |
230 | :project_id => 1 |
|
231 | :project_id => 1 | |
231 | ).count, |
|
232 | ).count, | |
232 | "TimeEntries still assigned to project specific activity" |
|
233 | "TimeEntries still assigned to project specific activity" | |
233 | end |
|
234 | end | |
234 | end |
|
235 | end |
General Comments 0
You need to be logged in to leave comments.
Login now