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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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 IssueStatusTest < ActiveSupport::TestCase
  19. fixtures :issue_statuses, :issues, :roles, :trackers
  20. def test_create
  21. status = IssueStatus.new :name => "Assigned"
  22. assert !status.save
  23. # status name uniqueness
  24. assert_equal 1, status.errors.count
  25. status.name = "Test Status"
  26. assert status.save
  27. assert !status.is_default
  28. end
  29. def test_destroy
  30. status = IssueStatus.find(3)
  31. assert_difference 'IssueStatus.count', -1 do
  32. assert status.destroy
  33. end
  34. assert_nil WorkflowTransition.first(:conditions => {:old_status_id => status.id})
  35. assert_nil WorkflowTransition.first(:conditions => {:new_status_id => status.id})
  36. end
  37. def test_destroy_status_in_use
  38. # Status assigned to an Issue
  39. status = Issue.find(1).status
  40. assert_raise(RuntimeError, "Can't delete status") { status.destroy }
  41. end
  42. def test_default
  43. status = IssueStatus.default
  44. assert_kind_of IssueStatus, status
  45. end
  46. def test_change_default
  47. status = IssueStatus.find(2)
  48. assert !status.is_default
  49. status.is_default = true
  50. assert status.save
  51. status.reload
  52. assert_equal status, IssueStatus.default
  53. assert !IssueStatus.find(1).is_default
  54. end
  55. def test_reorder_should_not_clear_default_status
  56. status = IssueStatus.default
  57. status.move_to_bottom
  58. status.reload
  59. assert status.is_default?
  60. end
  61. def test_new_statuses_allowed_to
  62. WorkflowTransition.delete_all
  63. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2, :author => false, :assignee => false)
  64. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3, :author => true, :assignee => false)
  65. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4, :author => false, :assignee => true)
  66. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5, :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.count(:conditions => {:done_ratio => 50})
  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.all(:conditions => {: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.all
  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. end