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.

issue_status_test.rb 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 IssueStatusTest < ActiveSupport::TestCase
  20. fixtures :projects, :users, :members, :member_roles, :roles,
  21. :groups_users,
  22. :trackers, :projects_trackers,
  23. :enabled_modules,
  24. :versions,
  25. :issue_statuses, :issue_categories, :issue_relations, :workflows,
  26. :enumerations,
  27. :issues, :journals, :journal_details,
  28. :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values
  29. def setup
  30. User.current = nil
  31. end
  32. def test_create
  33. status = IssueStatus.new :name => "Assigned"
  34. assert !status.save
  35. # status name uniqueness
  36. assert_equal 1, status.errors.count
  37. status.name = "Test Status"
  38. assert status.save
  39. end
  40. def test_destroy
  41. status = IssueStatus.find(3)
  42. assert_difference 'IssueStatus.count', -1 do
  43. assert status.destroy
  44. end
  45. assert_not WorkflowTransition.where(:old_status_id => status.id).exists?
  46. assert_not WorkflowTransition.where(:new_status_id => status.id).exists?
  47. end
  48. def test_destroy_status_in_use
  49. # Status assigned to an Issue
  50. status = Issue.find(1).status
  51. assert_raise(RuntimeError, "Cannot delete status") {status.destroy}
  52. end
  53. def test_new_statuses_allowed_to
  54. WorkflowTransition.delete_all
  55. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  56. :old_status_id => 1, :new_status_id => 2,
  57. :author => false, :assignee => false)
  58. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  59. :old_status_id => 1, :new_status_id => 3,
  60. :author => true, :assignee => false)
  61. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  62. :old_status_id => 1, :new_status_id => 4,
  63. :author => false, :assignee => true)
  64. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  65. :old_status_id => 1, :new_status_id => 5,
  66. :author => true, :assignee => true)
  67. status = IssueStatus.find(1)
  68. role = Role.find(1)
  69. tracker = Tracker.find(1)
  70. assert_equal [2], status.new_statuses_allowed_to([role], tracker, false, false).map(&:id)
  71. assert_equal [2], status.find_new_statuses_allowed_to([role], tracker, false, false).map(&:id)
  72. assert_equal [2, 3, 5], status.new_statuses_allowed_to([role], tracker, true, false).map(&:id)
  73. assert_equal [2, 3, 5], status.find_new_statuses_allowed_to([role], tracker, true, false).map(&:id)
  74. assert_equal [2, 4, 5], status.new_statuses_allowed_to([role], tracker, false, true).map(&:id)
  75. assert_equal [2, 4, 5], status.find_new_statuses_allowed_to([role], tracker, false, true).map(&:id)
  76. assert_equal [2, 3, 4, 5], status.new_statuses_allowed_to([role], tracker, true, true).map(&:id)
  77. assert_equal [2, 3, 4, 5], status.find_new_statuses_allowed_to([role], tracker, true, true).map(&:id)
  78. end
  79. def test_update_done_ratios_with_issue_done_ratio_set_to_issue_field_should_change_nothing
  80. IssueStatus.find(1).update_attribute(:default_done_ratio, 50)
  81. with_settings :issue_done_ratio => 'issue_field' do
  82. IssueStatus.update_issue_done_ratios
  83. assert_equal 0, Issue.where(:done_ratio => 50).count
  84. end
  85. end
  86. def test_update_done_ratios_with_issue_done_ratio_set_to_issue_status_should_update_issues
  87. IssueStatus.find(1).update_attribute(:default_done_ratio, 50)
  88. with_settings :issue_done_ratio => 'issue_status' do
  89. IssueStatus.update_issue_done_ratios
  90. issues = Issue.where(:status_id => 1)
  91. assert_equal [50], issues.map {|issue| issue.read_attribute(:done_ratio)}.uniq
  92. end
  93. end
  94. def test_sorted_scope
  95. assert_equal IssueStatus.all.sort, IssueStatus.sorted.to_a
  96. end
  97. def test_named_scope
  98. status = IssueStatus.named("resolved").first
  99. assert_not_nil status
  100. assert_equal "Resolved", status.name
  101. end
  102. def test_setting_status_as_closed_should_set_closed_on_for_issues_without_status_journal
  103. issue = Issue.generate!(:status_id => 1, :created_on => 2.days.ago)
  104. assert_nil issue.closed_on
  105. issue.status.update! :is_closed => true
  106. issue.reload
  107. assert issue.closed?
  108. assert_equal issue.created_on, issue.closed_on
  109. end
  110. def test_setting_status_as_closed_should_set_closed_on_for_issues_with_status_journal
  111. issue = Issue.generate!(:status_id => 1, :created_on => 2.days.ago)
  112. issue.init_journal(User.find(1))
  113. issue.status_id = 2
  114. issue.save!
  115. issue.status.update! :is_closed => true
  116. issue.reload
  117. assert issue.closed?
  118. assert_equal issue.journals.first.created_on, issue.closed_on
  119. end
  120. def test_setting_status_as_closed_should_not_set_closed_on_for_issues_with_other_status
  121. issue = Issue.generate!(:status_id => 2)
  122. IssueStatus.find(1).update! :is_closed => true
  123. issue.reload
  124. assert !issue.closed?
  125. assert_nil issue.closed_on
  126. end
  127. def test_issue_status_should_have_description
  128. issue_status = IssueStatus.find(1)
  129. assert_equal 'Description for New issue status', issue_status.description
  130. end
  131. end