annotate .svn/pristine/1e/1eeb2d3cf254cdaa3fced154da1af384e6d301db.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19 require 'workflows_controller'
Chris@909 20
Chris@909 21 # Re-raise errors caught by the controller.
Chris@909 22 class WorkflowsController; def rescue_action(e) raise e end; end
Chris@909 23
Chris@909 24 class WorkflowsControllerTest < ActionController::TestCase
Chris@909 25 fixtures :roles, :trackers, :workflows, :users, :issue_statuses
Chris@909 26
Chris@909 27 def setup
Chris@909 28 @controller = WorkflowsController.new
Chris@909 29 @request = ActionController::TestRequest.new
Chris@909 30 @response = ActionController::TestResponse.new
Chris@909 31 User.current = nil
Chris@909 32 @request.session[:user_id] = 1 # admin
Chris@909 33 end
Chris@909 34
Chris@909 35 def test_index
Chris@909 36 get :index
Chris@909 37 assert_response :success
Chris@909 38 assert_template 'index'
Chris@909 39
Chris@909 40 count = Workflow.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2')
Chris@909 41 assert_tag :tag => 'a', :content => count.to_s,
Chris@909 42 :attributes => { :href => '/workflows/edit?role_id=1&amp;tracker_id=2' }
Chris@909 43 end
Chris@909 44
Chris@909 45 def test_get_edit
Chris@909 46 get :edit
Chris@909 47 assert_response :success
Chris@909 48 assert_template 'edit'
Chris@909 49 assert_not_nil assigns(:roles)
Chris@909 50 assert_not_nil assigns(:trackers)
Chris@909 51 end
Chris@909 52
Chris@909 53 def test_get_edit_with_role_and_tracker
Chris@909 54 Workflow.delete_all
Chris@909 55 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
Chris@909 56 Workflow.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5)
Chris@909 57
Chris@909 58 get :edit, :role_id => 2, :tracker_id => 1
Chris@909 59 assert_response :success
Chris@909 60 assert_template 'edit'
Chris@909 61
Chris@909 62 # used status only
Chris@909 63 assert_not_nil assigns(:statuses)
Chris@909 64 assert_equal [2, 3, 5], assigns(:statuses).collect(&:id)
Chris@909 65
Chris@909 66 # allowed transitions
Chris@909 67 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
Chris@909 68 :name => 'issue_status[3][5][]',
Chris@909 69 :value => 'always',
Chris@909 70 :checked => 'checked' }
Chris@909 71 # not allowed
Chris@909 72 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
Chris@909 73 :name => 'issue_status[3][2][]',
Chris@909 74 :value => 'always',
Chris@909 75 :checked => nil }
Chris@909 76 # unused
Chris@909 77 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
Chris@909 78 :name => 'issue_status[1][1][]' }
Chris@909 79 end
Chris@909 80
Chris@909 81 def test_get_edit_with_role_and_tracker_and_all_statuses
Chris@909 82 Workflow.delete_all
Chris@909 83
Chris@909 84 get :edit, :role_id => 2, :tracker_id => 1, :used_statuses_only => '0'
Chris@909 85 assert_response :success
Chris@909 86 assert_template 'edit'
Chris@909 87
Chris@909 88 assert_not_nil assigns(:statuses)
Chris@909 89 assert_equal IssueStatus.count, assigns(:statuses).size
Chris@909 90
Chris@909 91 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
Chris@909 92 :name => 'issue_status[1][1][]',
Chris@909 93 :value => 'always',
Chris@909 94 :checked => nil }
Chris@909 95 end
Chris@909 96
Chris@909 97 def test_post_edit
Chris@909 98 post :edit, :role_id => 2, :tracker_id => 1,
Chris@909 99 :issue_status => {
Chris@909 100 '4' => {'5' => ['always']},
Chris@909 101 '3' => {'1' => ['always'], '2' => ['always']}
Chris@909 102 }
Chris@909 103 assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1'
Chris@909 104
Chris@909 105 assert_equal 3, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
Chris@909 106 assert_not_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2})
Chris@909 107 assert_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4})
Chris@909 108 end
Chris@909 109
Chris@909 110 def test_post_edit_with_additional_transitions
Chris@909 111 post :edit, :role_id => 2, :tracker_id => 1,
Chris@909 112 :issue_status => {
Chris@909 113 '4' => {'5' => ['always']},
Chris@909 114 '3' => {'1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee']}
Chris@909 115 }
Chris@909 116 assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1'
Chris@909 117
Chris@909 118 assert_equal 4, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
Chris@909 119
Chris@909 120 w = Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5})
Chris@909 121 assert ! w.author
Chris@909 122 assert ! w.assignee
Chris@909 123 w = Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1})
Chris@909 124 assert w.author
Chris@909 125 assert ! w.assignee
Chris@909 126 w = Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2})
Chris@909 127 assert ! w.author
Chris@909 128 assert w.assignee
Chris@909 129 w = Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4})
Chris@909 130 assert w.author
Chris@909 131 assert w.assignee
Chris@909 132 end
Chris@909 133
Chris@909 134 def test_clear_workflow
Chris@909 135 assert Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0
Chris@909 136
Chris@909 137 post :edit, :role_id => 2, :tracker_id => 1
Chris@909 138 assert_equal 0, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
Chris@909 139 end
Chris@909 140
Chris@909 141 def test_get_copy
Chris@909 142 get :copy
Chris@909 143 assert_response :success
Chris@909 144 assert_template 'copy'
Chris@909 145 end
Chris@909 146
Chris@909 147 def test_post_copy_one_to_one
Chris@909 148 source_transitions = status_transitions(:tracker_id => 1, :role_id => 2)
Chris@909 149
Chris@909 150 post :copy, :source_tracker_id => '1', :source_role_id => '2',
Chris@909 151 :target_tracker_ids => ['3'], :target_role_ids => ['1']
Chris@909 152 assert_response 302
Chris@909 153 assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1)
Chris@909 154 end
Chris@909 155
Chris@909 156 def test_post_copy_one_to_many
Chris@909 157 source_transitions = status_transitions(:tracker_id => 1, :role_id => 2)
Chris@909 158
Chris@909 159 post :copy, :source_tracker_id => '1', :source_role_id => '2',
Chris@909 160 :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3']
Chris@909 161 assert_response 302
Chris@909 162 assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 1)
Chris@909 163 assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1)
Chris@909 164 assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 3)
Chris@909 165 assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 3)
Chris@909 166 end
Chris@909 167
Chris@909 168 def test_post_copy_many_to_many
Chris@909 169 source_t2 = status_transitions(:tracker_id => 2, :role_id => 2)
Chris@909 170 source_t3 = status_transitions(:tracker_id => 3, :role_id => 2)
Chris@909 171
Chris@909 172 post :copy, :source_tracker_id => 'any', :source_role_id => '2',
Chris@909 173 :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3']
Chris@909 174 assert_response 302
Chris@909 175 assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 1)
Chris@909 176 assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1)
Chris@909 177 assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3)
Chris@909 178 assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3)
Chris@909 179 end
Chris@909 180
Chris@909 181 # Returns an array of status transitions that can be compared
Chris@909 182 def status_transitions(conditions)
Chris@909 183 Workflow.find(:all, :conditions => conditions,
Chris@909 184 :order => 'tracker_id, role_id, old_status_id, new_status_id').collect {|w| [w.old_status, w.new_status_id]}
Chris@909 185 end
Chris@909 186 end