Mercurial > hg > soundsoftware-site
comparison test/functional/workflows_controller_test.rb @ 1526:404aa68d4227
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 12:46:20 +0100 |
parents | dffacf8a6908 |
children |
comparison
equal
deleted
inserted
replaced
1493:a5f2bdf3b486 | 1526:404aa68d4227 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 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. |
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 require 'workflows_controller' | |
20 | |
21 # Re-raise errors caught by the controller. | |
22 class WorkflowsController; def rescue_action(e) raise e end; end | |
23 | 19 |
24 class WorkflowsControllerTest < ActionController::TestCase | 20 class WorkflowsControllerTest < ActionController::TestCase |
25 fixtures :roles, :trackers, :workflows, :users, :issue_statuses | 21 fixtures :roles, :trackers, :workflows, :users, :issue_statuses |
26 | 22 |
27 def setup | 23 def setup |
28 @controller = WorkflowsController.new | |
29 @request = ActionController::TestRequest.new | |
30 @response = ActionController::TestResponse.new | |
31 User.current = nil | 24 User.current = nil |
32 @request.session[:user_id] = 1 # admin | 25 @request.session[:user_id] = 1 # admin |
33 end | 26 end |
34 | 27 |
35 def test_index | 28 def test_index |
36 get :index | 29 get :index |
37 assert_response :success | 30 assert_response :success |
38 assert_template 'index' | 31 assert_template 'index' |
39 | 32 |
40 count = WorkflowTransition.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2') | 33 count = WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count |
41 assert_tag :tag => 'a', :content => count.to_s, | 34 assert_tag :tag => 'a', :content => count.to_s, |
42 :attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' } | 35 :attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' } |
43 end | 36 end |
44 | 37 |
45 def test_get_edit | 38 def test_get_edit |
100 '4' => {'5' => ['always']}, | 93 '4' => {'5' => ['always']}, |
101 '3' => {'1' => ['always'], '2' => ['always']} | 94 '3' => {'1' => ['always'], '2' => ['always']} |
102 } | 95 } |
103 assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' | 96 assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' |
104 | 97 |
105 assert_equal 3, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) | 98 assert_equal 3, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count |
106 assert_not_nil WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2}) | 99 assert_not_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first |
107 assert_nil WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4}) | 100 assert_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4).first |
108 end | 101 end |
109 | 102 |
110 def test_post_edit_with_additional_transitions | 103 def test_post_edit_with_additional_transitions |
111 post :edit, :role_id => 2, :tracker_id => 1, | 104 post :edit, :role_id => 2, :tracker_id => 1, |
112 :issue_status => { | 105 :issue_status => { |
113 '4' => {'5' => ['always']}, | 106 '4' => {'5' => ['always']}, |
114 '3' => {'1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee']} | 107 '3' => {'1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee']} |
115 } | 108 } |
116 assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' | 109 assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' |
117 | 110 |
118 assert_equal 4, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) | 111 assert_equal 4, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count |
119 | 112 |
120 w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5}) | 113 w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5).first |
121 assert ! w.author | 114 assert ! w.author |
122 assert ! w.assignee | 115 assert ! w.assignee |
123 w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1}) | 116 w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1).first |
124 assert w.author | 117 assert w.author |
125 assert ! w.assignee | 118 assert ! w.assignee |
126 w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2}) | 119 w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first |
127 assert ! w.author | 120 assert ! w.author |
128 assert w.assignee | 121 assert w.assignee |
129 w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4}) | 122 w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4).first |
130 assert w.author | 123 assert w.author |
131 assert w.assignee | 124 assert w.assignee |
132 end | 125 end |
133 | 126 |
134 def test_clear_workflow | 127 def test_clear_workflow |
135 assert WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0 | 128 assert WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count > 0 |
136 | 129 |
137 post :edit, :role_id => 2, :tracker_id => 1 | 130 post :edit, :role_id => 1, :tracker_id => 2 |
138 assert_equal 0, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) | 131 assert_equal 0, WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count |
139 end | 132 end |
140 | 133 |
141 def test_get_permissions | 134 def test_get_permissions |
142 get :permissions | 135 get :permissions |
143 | 136 |
205 assert_select 'option[value=readonly]', :text => 'Read-only' | 198 assert_select 'option[value=readonly]', :text => 'Read-only' |
206 assert_select 'option[value=required]', 0 | 199 assert_select 'option[value=required]', 0 |
207 end | 200 end |
208 end | 201 end |
209 | 202 |
203 def test_get_permissions_should_disable_hidden_custom_fields | |
204 cf1 = IssueCustomField.generate!(:tracker_ids => [1], :visible => true) | |
205 cf2 = IssueCustomField.generate!(:tracker_ids => [1], :visible => false, :role_ids => [1]) | |
206 cf3 = IssueCustomField.generate!(:tracker_ids => [1], :visible => false, :role_ids => [1, 2]) | |
207 | |
208 get :permissions, :role_id => 2, :tracker_id => 1 | |
209 assert_response :success | |
210 assert_template 'permissions' | |
211 | |
212 assert_select 'select[name=?]:not(.disabled)', "permissions[#{cf1.id}][1]" | |
213 assert_select 'select[name=?]:not(.disabled)', "permissions[#{cf3.id}][1]" | |
214 | |
215 assert_select 'select[name=?][disabled=disabled]', "permissions[#{cf2.id}][1]" do | |
216 assert_select 'option[value=][selected=selected]', :text => 'Hidden' | |
217 end | |
218 end | |
219 | |
210 def test_get_permissions_with_role_and_tracker_and_all_statuses | 220 def test_get_permissions_with_role_and_tracker_and_all_statuses |
211 WorkflowTransition.delete_all | 221 WorkflowTransition.delete_all |
212 | 222 |
213 get :permissions, :role_id => 1, :tracker_id => 2, :used_statuses_only => '0' | 223 get :permissions, :role_id => 1, :tracker_id => 2, :used_statuses_only => '0' |
214 assert_response :success | 224 assert_response :success |
302 assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) | 312 assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) |
303 assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) | 313 assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) |
304 assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) | 314 assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) |
305 end | 315 end |
306 | 316 |
317 def test_post_copy_with_incomplete_source_specification_should_fail | |
318 assert_no_difference 'WorkflowRule.count' do | |
319 post :copy, | |
320 :source_tracker_id => '', :source_role_id => '2', | |
321 :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
322 assert_response 200 | |
323 assert_select 'div.flash.error', :text => 'Please select a source tracker or role' | |
324 end | |
325 end | |
326 | |
327 def test_post_copy_with_incomplete_target_specification_should_fail | |
328 assert_no_difference 'WorkflowRule.count' do | |
329 post :copy, | |
330 :source_tracker_id => '1', :source_role_id => '2', | |
331 :target_tracker_ids => ['2', '3'] | |
332 assert_response 200 | |
333 assert_select 'div.flash.error', :text => 'Please select target tracker(s) and role(s)' | |
334 end | |
335 end | |
336 | |
307 # Returns an array of status transitions that can be compared | 337 # Returns an array of status transitions that can be compared |
308 def status_transitions(conditions) | 338 def status_transitions(conditions) |
309 WorkflowTransition.find(:all, :conditions => conditions, | 339 WorkflowTransition. |
310 :order => 'tracker_id, role_id, old_status_id, new_status_id').collect {|w| [w.old_status, w.new_status_id]} | 340 where(conditions). |
341 order('tracker_id, role_id, old_status_id, new_status_id'). | |
342 collect {|w| [w.old_status, w.new_status_id]} | |
311 end | 343 end |
312 end | 344 end |