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 3.8KB

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