| 
									
										
										
										
											2019-03-16 15:03:47 +00:00
										 |  |  | # frozen_string_literal: true | 
					
						
							| 
									
										
										
										
											2019-03-15 01:32:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-25 02:54:47 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2022-01-02 05:29:10 +00:00
										 |  |  | # Copyright (C) 2006-2022  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2014-02-25 02:54:47 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require File.expand_path('../../test_helper', __FILE__) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WorkflowTransitionTest < ActiveSupport::TestCase | 
					
						
							|  |  |  |   fixtures :roles, :trackers, :issue_statuses | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def setup | 
					
						
							| 
									
										
										
										
											2018-12-16 17:23:31 +00:00
										 |  |  |     User.current = nil | 
					
						
							| 
									
										
										
										
											2014-02-25 02:54:47 +00:00
										 |  |  |     WorkflowTransition.delete_all | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_replace_transitions_should_create_enabled_transitions | 
					
						
							| 
									
										
										
										
											2020-12-03 13:19:56 +00:00
										 |  |  |     w = WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | 
					
						
							|  |  |  |                                    :old_status_id => 1, :new_status_id => 2) | 
					
						
							| 
									
										
										
										
											2014-02-25 02:54:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     transitions = {'1' => { | 
					
						
							|  |  |  |       '2' => {'always' => '1'}, | 
					
						
							|  |  |  |       '3' => {'always' => '1'} | 
					
						
							|  |  |  |     }} | 
					
						
							|  |  |  |     assert_difference 'WorkflowTransition.count' do | 
					
						
							|  |  |  |       WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-12-03 13:19:56 +00:00
										 |  |  |     assert WorkflowTransition.where(:role_id => 1, :tracker_id => 1, | 
					
						
							|  |  |  |                                     :old_status_id => 1, | 
					
						
							|  |  |  |                                     :new_status_id => 3).exists? | 
					
						
							| 
									
										
										
										
											2014-02-25 02:54:47 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_replace_transitions_should_delete_disabled_transitions | 
					
						
							| 
									
										
										
										
											2020-12-03 13:19:56 +00:00
										 |  |  |     w1 = WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | 
					
						
							|  |  |  |                                     :old_status_id => 1, :new_status_id => 2) | 
					
						
							|  |  |  |     w2 = WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | 
					
						
							|  |  |  |                                     :old_status_id => 1, :new_status_id => 3) | 
					
						
							| 
									
										
										
										
											2014-02-25 02:54:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     transitions = {'1' => { | 
					
						
							|  |  |  |       '2' => {'always' => '0'}, | 
					
						
							|  |  |  |       '3' => {'always' => '1'} | 
					
						
							|  |  |  |     }} | 
					
						
							|  |  |  |     assert_difference 'WorkflowTransition.count', -1 do | 
					
						
							|  |  |  |       WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     assert !WorkflowTransition.exists?(w1.id) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_replace_transitions_should_create_enabled_additional_transitions | 
					
						
							|  |  |  |     transitions = {'1' => { | 
					
						
							|  |  |  |       '2' => {'always' => '0', 'assignee' => '0', 'author' => '1'} | 
					
						
							|  |  |  |     }} | 
					
						
							|  |  |  |     assert_difference 'WorkflowTransition.count' do | 
					
						
							|  |  |  |       WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-12-03 13:19:56 +00:00
										 |  |  |     w = WorkflowTransition.where(:role_id => 1, :tracker_id => 1, | 
					
						
							|  |  |  |                                  :old_status_id => 1, :new_status_id => 2).first | 
					
						
							| 
									
										
										
										
											2014-02-25 02:54:47 +00:00
										 |  |  |     assert w | 
					
						
							|  |  |  |     assert_equal false, w.assignee | 
					
						
							|  |  |  |     assert_equal true, w.author | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_replace_transitions_should_delete_disabled_additional_transitions | 
					
						
							| 
									
										
										
										
											2020-12-03 13:19:56 +00:00
										 |  |  |     w = WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | 
					
						
							|  |  |  |                                    :old_status_id => 1, :new_status_id => 2, | 
					
						
							|  |  |  |                                    :assignee => true) | 
					
						
							| 
									
										
										
										
											2014-02-25 02:54:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     transitions = {'1' => { | 
					
						
							|  |  |  |       '2' => {'always' => '0', 'assignee' => '0', 'author' => '0'} | 
					
						
							|  |  |  |     }} | 
					
						
							|  |  |  |     assert_difference 'WorkflowTransition.count', -1 do | 
					
						
							|  |  |  |       WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     assert !WorkflowTransition.exists?(w.id) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_replace_transitions_should_update_additional_transitions | 
					
						
							| 
									
										
										
										
											2020-12-03 13:19:56 +00:00
										 |  |  |     WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | 
					
						
							|  |  |  |                                :old_status_id => 1, :new_status_id => 2, | 
					
						
							|  |  |  |                                :assignee => true) | 
					
						
							| 
									
										
										
										
											2014-02-25 02:54:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     transitions = {'1' => { | 
					
						
							|  |  |  |       '2' => {'always' => '0', 'assignee' => '0', 'author' => '1'} | 
					
						
							|  |  |  |     }} | 
					
						
							|  |  |  |     assert_no_difference 'WorkflowTransition.count' do | 
					
						
							|  |  |  |       WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-12-03 13:19:56 +00:00
										 |  |  |     w = WorkflowTransition.where(:role_id => 1, :tracker_id => 1, | 
					
						
							|  |  |  |                                  :old_status_id => 1, :new_status_id => 2).first | 
					
						
							| 
									
										
										
										
											2014-02-25 02:54:47 +00:00
										 |  |  |     assert w | 
					
						
							|  |  |  |     assert_equal false, w.assignee | 
					
						
							|  |  |  |     assert_equal true, w.author | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |