comparison test/functional/workflows_controller_test.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 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.
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
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
302 assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) 295 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) 296 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) 297 assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3)
305 end 298 end
306 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
307 # Returns an array of status transitions that can be compared 320 # Returns an array of status transitions that can be compared
308 def status_transitions(conditions) 321 def status_transitions(conditions)
309 WorkflowTransition.find(:all, :conditions => conditions, 322 WorkflowTransition.
310 :order => 'tracker_id, role_id, old_status_id, new_status_id').collect {|w| [w.old_status, w.new_status_id]} 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]}
311 end 327 end
312 end 328 end