You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

workflow_transition_test.rb 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class WorkflowTransitionTest < ActiveSupport::TestCase
  20. fixtures :roles, :trackers, :issue_statuses
  21. def setup
  22. User.current = nil
  23. WorkflowTransition.delete_all
  24. end
  25. def test_replace_transitions_should_create_enabled_transitions
  26. w = WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  27. :old_status_id => 1, :new_status_id => 2)
  28. transitions = {'1' => {
  29. '2' => {'always' => '1'},
  30. '3' => {'always' => '1'}
  31. }}
  32. assert_difference 'WorkflowTransition.count' do
  33. WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions)
  34. end
  35. assert WorkflowTransition.where(:role_id => 1, :tracker_id => 1,
  36. :old_status_id => 1,
  37. :new_status_id => 3).exists?
  38. end
  39. def test_replace_transitions_should_delete_disabled_transitions
  40. w1 = WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  41. :old_status_id => 1, :new_status_id => 2)
  42. w2 = WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  43. :old_status_id => 1, :new_status_id => 3)
  44. transitions = {'1' => {
  45. '2' => {'always' => '0'},
  46. '3' => {'always' => '1'}
  47. }}
  48. assert_difference 'WorkflowTransition.count', -1 do
  49. WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions)
  50. end
  51. assert !WorkflowTransition.exists?(w1.id)
  52. end
  53. def test_replace_transitions_should_create_enabled_additional_transitions
  54. transitions = {'1' => {
  55. '2' => {'always' => '0', 'assignee' => '0', 'author' => '1'}
  56. }}
  57. assert_difference 'WorkflowTransition.count' do
  58. WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions)
  59. end
  60. w = WorkflowTransition.where(:role_id => 1, :tracker_id => 1,
  61. :old_status_id => 1, :new_status_id => 2).first
  62. assert w
  63. assert_equal false, w.assignee
  64. assert_equal true, w.author
  65. end
  66. def test_replace_transitions_should_delete_disabled_additional_transitions
  67. w = WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  68. :old_status_id => 1, :new_status_id => 2,
  69. :assignee => true)
  70. transitions = {'1' => {
  71. '2' => {'always' => '0', 'assignee' => '0', 'author' => '0'}
  72. }}
  73. assert_difference 'WorkflowTransition.count', -1 do
  74. WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions)
  75. end
  76. assert !WorkflowTransition.exists?(w.id)
  77. end
  78. def test_replace_transitions_should_update_additional_transitions
  79. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  80. :old_status_id => 1, :new_status_id => 2,
  81. :assignee => true)
  82. transitions = {'1' => {
  83. '2' => {'always' => '0', 'assignee' => '0', 'author' => '1'}
  84. }}
  85. assert_no_difference 'WorkflowTransition.count' do
  86. WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions)
  87. end
  88. w = WorkflowTransition.where(:role_id => 1, :tracker_id => 1,
  89. :old_status_id => 1, :new_status_id => 2).first
  90. assert w
  91. assert_equal false, w.assignee
  92. assert_equal true, w.author
  93. end
  94. end