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_statuses_controller_test.rb 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 IssueStatusesControllerTest < Redmine::ControllerTest
  20. fixtures :issue_statuses, :issues, :users, :trackers, :workflows
  21. def setup
  22. User.current = nil
  23. @request.session[:user_id] = 1 # admin
  24. end
  25. def test_index
  26. get :index
  27. assert_response :success
  28. assert_select 'table.issue_statuses'
  29. end
  30. def test_index_by_anonymous_should_redirect_to_login_form
  31. @request.session[:user_id] = nil
  32. get :index
  33. assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fissue_statuses'
  34. end
  35. def test_index_by_user_should_respond_with_406
  36. @request.session[:user_id] = 2
  37. get :index
  38. assert_response 406
  39. end
  40. def test_index_should_show_warning_when_no_workflow_is_defined
  41. status = IssueStatus.new :name => "No workflow"
  42. status.save!
  43. get :index
  44. assert_response :success
  45. assert_select 'table.issue_statuses tbody' do
  46. assert_select 'tr:not(:last-of-type) span.icon-warning', :count => 0
  47. assert_select 'tr:last-of-type' do
  48. assert_select 'td.name', :text => status.name
  49. assert_select 'td span.icon-warning',
  50. :text => /#{I18n.t(:text_status_no_workflow)}/
  51. end
  52. end
  53. end
  54. def test_new
  55. get :new
  56. assert_response :success
  57. assert_select 'input[name=?]', 'issue_status[name]'
  58. end
  59. def test_create
  60. assert_difference 'IssueStatus.count' do
  61. post(
  62. :create,
  63. :params => {
  64. :issue_status => {
  65. :name => 'New status'
  66. }
  67. }
  68. )
  69. end
  70. assert_redirected_to :action => 'index'
  71. status = IssueStatus.order('id DESC').first
  72. assert_equal 'New status', status.name
  73. end
  74. def test_create_with_failure
  75. post(
  76. :create,
  77. :params => {
  78. :issue_status => {
  79. :name => ''
  80. }
  81. }
  82. )
  83. assert_response :success
  84. assert_select_error /name cannot be blank/i
  85. end
  86. def test_edit
  87. get(:edit, :params => {:id => '3'})
  88. assert_response :success
  89. assert_select 'input[name=?][value=?]', 'issue_status[name]', 'Resolved'
  90. end
  91. def test_update
  92. put(
  93. :update,
  94. :params => {
  95. :id => '3',
  96. :issue_status => {
  97. :name => 'Renamed status'
  98. }
  99. }
  100. )
  101. assert_redirected_to :action => 'index'
  102. status = IssueStatus.find(3)
  103. assert_equal 'Renamed status', status.name
  104. end
  105. def test_update_with_failure
  106. put(
  107. :update,
  108. :params => {
  109. :id => '3',
  110. :issue_status => {
  111. :name => ''
  112. }
  113. }
  114. )
  115. assert_response :success
  116. assert_select_error /name cannot be blank/i
  117. end
  118. def test_destroy
  119. Issue.where(:status_id => 1).delete_all
  120. Tracker.where(:default_status_id => 1).delete_all
  121. assert_difference 'IssueStatus.count', -1 do
  122. delete(:destroy, :params => {:id => '1'})
  123. end
  124. assert_redirected_to :action => 'index'
  125. assert_nil IssueStatus.find_by_id(1)
  126. end
  127. def test_destroy_should_block_if_status_is_used_by_issues
  128. assert Issue.where(:status_id => 1).any?
  129. Tracker.where(:default_status_id => 1).delete_all
  130. assert_no_difference 'IssueStatus.count' do
  131. delete(:destroy, :params => {:id => '1'})
  132. end
  133. assert_redirected_to :action => 'index'
  134. assert_not_nil IssueStatus.find_by_id(1)
  135. end
  136. def test_destroy_should_block_if_status_is_used_as_tracker_default_status
  137. Issue.where(:status_id => 1).delete_all
  138. assert Tracker.where(:default_status_id => 1).any?
  139. assert_no_difference 'IssueStatus.count' do
  140. delete(:destroy, :params => {:id => '1'})
  141. end
  142. assert_redirected_to :action => 'index'
  143. assert_not_nil IssueStatus.find_by_id(1)
  144. end
  145. def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_field
  146. with_settings :issue_done_ratio => 'issue_field' do
  147. post :update_issue_done_ratio
  148. assert_match /not updated/, flash[:error].to_s
  149. assert_redirected_to '/issue_statuses'
  150. end
  151. end
  152. def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_status
  153. with_settings :issue_done_ratio => 'issue_status' do
  154. post :update_issue_done_ratio
  155. assert_match /Issue done ratios updated/, flash[:notice].to_s
  156. assert_redirected_to '/issue_statuses'
  157. end
  158. end
  159. end