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_test.rb 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 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 File.expand_path('../../test_helper', __FILE__)
  19. class WorkflowTest < ActiveSupport::TestCase
  20. fixtures :roles, :trackers, :issue_statuses
  21. def setup
  22. User.current = nil
  23. end
  24. def test_copy
  25. WorkflowTransition.delete_all
  26. WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
  27. :old_status_id => 1, :new_status_id => 2)
  28. WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
  29. :old_status_id => 1, :new_status_id => 3,
  30. :assignee => true)
  31. WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
  32. :old_status_id => 1, :new_status_id => 4,
  33. :author => true)
  34. assert_difference 'WorkflowTransition.count', 3 do
  35. WorkflowTransition.copy(Tracker.find(2), Role.find(1), Tracker.find(3), Role.find(2))
  36. end
  37. assert WorkflowTransition.where(:role_id => 2, :tracker_id => 3,
  38. :old_status_id => 1, :new_status_id => 2,
  39. :author => false, :assignee => false).first
  40. assert WorkflowTransition.where(:role_id => 2, :tracker_id => 3,
  41. :old_status_id => 1, :new_status_id => 3,
  42. :author => false, :assignee => true).first
  43. assert WorkflowTransition.where(:role_id => 2, :tracker_id => 3,
  44. :old_status_id => 1, :new_status_id => 4,
  45. :author => true, :assignee => false).first
  46. end
  47. def test_workflow_permission_should_validate_rule
  48. wp = WorkflowPermission.new(:role_id => 1, :tracker_id => 1,
  49. :old_status_id => 1, :field_name => 'due_date')
  50. assert !wp.save
  51. wp.rule = 'foo'
  52. assert !wp.save
  53. wp.rule = 'required'
  54. assert wp.save
  55. wp.rule = 'readonly'
  56. assert wp.save
  57. end
  58. def test_workflow_permission_should_validate_field_name
  59. wp = WorkflowPermission.new(:role_id => 1, :tracker_id => 1,
  60. :old_status_id => 1, :rule => 'required')
  61. assert !wp.save
  62. wp.field_name = 'foo'
  63. assert !wp.save
  64. wp.field_name = 'due_date'
  65. assert wp.save
  66. wp.field_name = '1'
  67. assert wp.save
  68. end
  69. end