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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 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. WorkflowTransition.delete_all
  22. end
  23. def test_replace_transitions_should_create_enabled_transitions
  24. w = WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2)
  25. transitions = {'1' => {
  26. '2' => {'always' => '1'},
  27. '3' => {'always' => '1'}
  28. }}
  29. assert_difference 'WorkflowTransition.count' do
  30. WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions)
  31. end
  32. assert WorkflowTransition.where(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3).exists?
  33. end
  34. def test_replace_transitions_should_delete_disabled_transitions
  35. w1 = WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2)
  36. w2 = WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
  37. transitions = {'1' => {
  38. '2' => {'always' => '0'},
  39. '3' => {'always' => '1'}
  40. }}
  41. assert_difference 'WorkflowTransition.count', -1 do
  42. WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions)
  43. end
  44. assert !WorkflowTransition.exists?(w1.id)
  45. end
  46. def test_replace_transitions_should_create_enabled_additional_transitions
  47. transitions = {'1' => {
  48. '2' => {'always' => '0', 'assignee' => '0', 'author' => '1'}
  49. }}
  50. assert_difference 'WorkflowTransition.count' do
  51. WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions)
  52. end
  53. w = WorkflowTransition.where(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2).first
  54. assert w
  55. assert_equal false, w.assignee
  56. assert_equal true, w.author
  57. end
  58. def test_replace_transitions_should_delete_disabled_additional_transitions
  59. w = WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2, :assignee => true)
  60. transitions = {'1' => {
  61. '2' => {'always' => '0', 'assignee' => '0', 'author' => '0'}
  62. }}
  63. assert_difference 'WorkflowTransition.count', -1 do
  64. WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions)
  65. end
  66. assert !WorkflowTransition.exists?(w.id)
  67. end
  68. def test_replace_transitions_should_update_additional_transitions
  69. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2, :assignee => true)
  70. transitions = {'1' => {
  71. '2' => {'always' => '0', 'assignee' => '0', 'author' => '1'}
  72. }}
  73. assert_no_difference 'WorkflowTransition.count' do
  74. WorkflowTransition.replace_transitions(Tracker.find(1), Role.find(1), transitions)
  75. end
  76. w = WorkflowTransition.where(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2).first
  77. assert w
  78. assert_equal false, w.assignee
  79. assert_equal true, w.author
  80. end
  81. end