Mercurial > hg > soundsoftware-site
comparison .svn/pristine/a6/a649e6e13fa94c6da3001118983e1f589fe01ce6.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
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 | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../test_helper', __FILE__) | |
19 | |
20 class WorkflowsControllerTest < ActionController::TestCase | |
21 fixtures :roles, :trackers, :workflows, :users, :issue_statuses | |
22 | |
23 def setup | |
24 User.current = nil | |
25 @request.session[:user_id] = 1 # admin | |
26 end | |
27 | |
28 def test_index | |
29 get :index | |
30 assert_response :success | |
31 assert_template 'index' | |
32 | |
33 count = WorkflowTransition.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2') | |
34 assert_tag :tag => 'a', :content => count.to_s, | |
35 :attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' } | |
36 end | |
37 | |
38 def test_get_edit | |
39 get :edit | |
40 assert_response :success | |
41 assert_template 'edit' | |
42 assert_not_nil assigns(:roles) | |
43 assert_not_nil assigns(:trackers) | |
44 end | |
45 | |
46 def test_get_edit_with_role_and_tracker | |
47 WorkflowTransition.delete_all | |
48 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) | |
49 WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) | |
50 | |
51 get :edit, :role_id => 2, :tracker_id => 1 | |
52 assert_response :success | |
53 assert_template 'edit' | |
54 | |
55 # used status only | |
56 assert_not_nil assigns(:statuses) | |
57 assert_equal [2, 3, 5], assigns(:statuses).collect(&:id) | |
58 | |
59 # allowed transitions | |
60 assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
61 :name => 'issue_status[3][5][]', | |
62 :value => 'always', | |
63 :checked => 'checked' } | |
64 # not allowed | |
65 assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
66 :name => 'issue_status[3][2][]', | |
67 :value => 'always', | |
68 :checked => nil } | |
69 # unused | |
70 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
71 :name => 'issue_status[1][1][]' } | |
72 end | |
73 | |
74 def test_get_edit_with_role_and_tracker_and_all_statuses | |
75 WorkflowTransition.delete_all | |
76 | |
77 get :edit, :role_id => 2, :tracker_id => 1, :used_statuses_only => '0' | |
78 assert_response :success | |
79 assert_template 'edit' | |
80 | |
81 assert_not_nil assigns(:statuses) | |
82 assert_equal IssueStatus.count, assigns(:statuses).size | |
83 | |
84 assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
85 :name => 'issue_status[1][1][]', | |
86 :value => 'always', | |
87 :checked => nil } | |
88 end | |
89 | |
90 def test_post_edit | |
91 post :edit, :role_id => 2, :tracker_id => 1, | |
92 :issue_status => { | |
93 '4' => {'5' => ['always']}, | |
94 '3' => {'1' => ['always'], '2' => ['always']} | |
95 } | |
96 assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' | |
97 | |
98 assert_equal 3, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count | |
99 assert_not_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first | |
100 assert_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4).first | |
101 end | |
102 | |
103 def test_post_edit_with_additional_transitions | |
104 post :edit, :role_id => 2, :tracker_id => 1, | |
105 :issue_status => { | |
106 '4' => {'5' => ['always']}, | |
107 '3' => {'1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee']} | |
108 } | |
109 assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' | |
110 | |
111 assert_equal 4, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count | |
112 | |
113 w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5).first | |
114 assert ! w.author | |
115 assert ! w.assignee | |
116 w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1).first | |
117 assert w.author | |
118 assert ! w.assignee | |
119 w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first | |
120 assert ! w.author | |
121 assert w.assignee | |
122 w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4).first | |
123 assert w.author | |
124 assert w.assignee | |
125 end | |
126 | |
127 def test_clear_workflow | |
128 assert WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0 | |
129 | |
130 post :edit, :role_id => 2, :tracker_id => 1 | |
131 assert_equal 0, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) | |
132 end | |
133 | |
134 def test_get_permissions | |
135 get :permissions | |
136 | |
137 assert_response :success | |
138 assert_template 'permissions' | |
139 assert_not_nil assigns(:roles) | |
140 assert_not_nil assigns(:trackers) | |
141 end | |
142 | |
143 def test_get_permissions_with_role_and_tracker | |
144 WorkflowPermission.delete_all | |
145 WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') | |
146 WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') | |
147 WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') | |
148 | |
149 get :permissions, :role_id => 1, :tracker_id => 2 | |
150 assert_response :success | |
151 assert_template 'permissions' | |
152 | |
153 assert_select 'input[name=role_id][value=1]' | |
154 assert_select 'input[name=tracker_id][value=2]' | |
155 | |
156 # Required field | |
157 assert_select 'select[name=?]', 'permissions[assigned_to_id][2]' do | |
158 assert_select 'option[value=]' | |
159 assert_select 'option[value=][selected=selected]', 0 | |
160 assert_select 'option[value=readonly]', :text => 'Read-only' | |
161 assert_select 'option[value=readonly][selected=selected]', 0 | |
162 assert_select 'option[value=required]', :text => 'Required' | |
163 assert_select 'option[value=required][selected=selected]' | |
164 end | |
165 | |
166 # Read-only field | |
167 assert_select 'select[name=?]', 'permissions[fixed_version_id][3]' do | |
168 assert_select 'option[value=]' | |
169 assert_select 'option[value=][selected=selected]', 0 | |
170 assert_select 'option[value=readonly]', :text => 'Read-only' | |
171 assert_select 'option[value=readonly][selected=selected]' | |
172 assert_select 'option[value=required]', :text => 'Required' | |
173 assert_select 'option[value=required][selected=selected]', 0 | |
174 end | |
175 | |
176 # Other field | |
177 assert_select 'select[name=?]', 'permissions[due_date][3]' do | |
178 assert_select 'option[value=]' | |
179 assert_select 'option[value=][selected=selected]', 0 | |
180 assert_select 'option[value=readonly]', :text => 'Read-only' | |
181 assert_select 'option[value=readonly][selected=selected]', 0 | |
182 assert_select 'option[value=required]', :text => 'Required' | |
183 assert_select 'option[value=required][selected=selected]', 0 | |
184 end | |
185 end | |
186 | |
187 def test_get_permissions_with_required_custom_field_should_not_show_required_option | |
188 cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :tracker_ids => [1], :is_required => true) | |
189 | |
190 get :permissions, :role_id => 1, :tracker_id => 1 | |
191 assert_response :success | |
192 assert_template 'permissions' | |
193 | |
194 # Custom field that is always required | |
195 # The default option is "(Required)" | |
196 assert_select 'select[name=?]', "permissions[#{cf.id}][3]" do | |
197 assert_select 'option[value=]' | |
198 assert_select 'option[value=readonly]', :text => 'Read-only' | |
199 assert_select 'option[value=required]', 0 | |
200 end | |
201 end | |
202 | |
203 def test_get_permissions_with_role_and_tracker_and_all_statuses | |
204 WorkflowTransition.delete_all | |
205 | |
206 get :permissions, :role_id => 1, :tracker_id => 2, :used_statuses_only => '0' | |
207 assert_response :success | |
208 assert_equal IssueStatus.sorted.all, assigns(:statuses) | |
209 end | |
210 | |
211 def test_post_permissions | |
212 WorkflowPermission.delete_all | |
213 | |
214 post :permissions, :role_id => 1, :tracker_id => 2, :permissions => { | |
215 'assigned_to_id' => {'1' => '', '2' => 'readonly', '3' => ''}, | |
216 'fixed_version_id' => {'1' => 'required', '2' => 'readonly', '3' => ''}, | |
217 'due_date' => {'1' => '', '2' => '', '3' => ''}, | |
218 } | |
219 assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' | |
220 | |
221 workflows = WorkflowPermission.all | |
222 assert_equal 3, workflows.size | |
223 workflows.each do |workflow| | |
224 assert_equal 1, workflow.role_id | |
225 assert_equal 2, workflow.tracker_id | |
226 end | |
227 assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'assigned_to_id' && wf.rule == 'readonly'} | |
228 assert workflows.detect {|wf| wf.old_status_id == 1 && wf.field_name == 'fixed_version_id' && wf.rule == 'required'} | |
229 assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'fixed_version_id' && wf.rule == 'readonly'} | |
230 end | |
231 | |
232 def test_post_permissions_should_clear_permissions | |
233 WorkflowPermission.delete_all | |
234 WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') | |
235 WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') | |
236 wf1 = WorkflowPermission.create!(:role_id => 1, :tracker_id => 3, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') | |
237 wf2 = WorkflowPermission.create!(:role_id => 2, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') | |
238 | |
239 post :permissions, :role_id => 1, :tracker_id => 2 | |
240 assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' | |
241 | |
242 workflows = WorkflowPermission.all | |
243 assert_equal 2, workflows.size | |
244 assert wf1.reload | |
245 assert wf2.reload | |
246 end | |
247 | |
248 def test_get_copy | |
249 get :copy | |
250 assert_response :success | |
251 assert_template 'copy' | |
252 assert_select 'select[name=source_tracker_id]' do | |
253 assert_select 'option[value=1]', :text => 'Bug' | |
254 end | |
255 assert_select 'select[name=source_role_id]' do | |
256 assert_select 'option[value=2]', :text => 'Developer' | |
257 end | |
258 assert_select 'select[name=?]', 'target_tracker_ids[]' do | |
259 assert_select 'option[value=3]', :text => 'Support request' | |
260 end | |
261 assert_select 'select[name=?]', 'target_role_ids[]' do | |
262 assert_select 'option[value=1]', :text => 'Manager' | |
263 end | |
264 end | |
265 | |
266 def test_post_copy_one_to_one | |
267 source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) | |
268 | |
269 post :copy, :source_tracker_id => '1', :source_role_id => '2', | |
270 :target_tracker_ids => ['3'], :target_role_ids => ['1'] | |
271 assert_response 302 | |
272 assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) | |
273 end | |
274 | |
275 def test_post_copy_one_to_many | |
276 source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) | |
277 | |
278 post :copy, :source_tracker_id => '1', :source_role_id => '2', | |
279 :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
280 assert_response 302 | |
281 assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 1) | |
282 assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) | |
283 assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 3) | |
284 assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 3) | |
285 end | |
286 | |
287 def test_post_copy_many_to_many | |
288 source_t2 = status_transitions(:tracker_id => 2, :role_id => 2) | |
289 source_t3 = status_transitions(:tracker_id => 3, :role_id => 2) | |
290 | |
291 post :copy, :source_tracker_id => 'any', :source_role_id => '2', | |
292 :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
293 assert_response 302 | |
294 assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 1) | |
295 assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) | |
296 assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) | |
297 assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) | |
298 end | |
299 | |
300 def test_post_copy_with_incomplete_source_specification_should_fail | |
301 assert_no_difference 'WorkflowRule.count' do | |
302 post :copy, | |
303 :source_tracker_id => '', :source_role_id => '2', | |
304 :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
305 assert_response 200 | |
306 assert_select 'div.flash.error', :text => 'Please select a source tracker or role' | |
307 end | |
308 end | |
309 | |
310 def test_post_copy_with_incomplete_target_specification_should_fail | |
311 assert_no_difference 'WorkflowRule.count' do | |
312 post :copy, | |
313 :source_tracker_id => '1', :source_role_id => '2', | |
314 :target_tracker_ids => ['2', '3'] | |
315 assert_response 200 | |
316 assert_select 'div.flash.error', :text => 'Please select target tracker(s) and role(s)' | |
317 end | |
318 end | |
319 | |
320 # Returns an array of status transitions that can be compared | |
321 def status_transitions(conditions) | |
322 WorkflowTransition. | |
323 where(conditions). | |
324 order('tracker_id, role_id, old_status_id, new_status_id'). | |
325 all. | |
326 collect {|w| [w.old_status, w.new_status_id]} | |
327 end | |
328 end |