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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 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. assert_select 'textarea[name=?]', 'issue_status[description]'
  59. end
  60. def test_create
  61. assert_difference 'IssueStatus.count' do
  62. post(
  63. :create,
  64. :params => {
  65. :issue_status => {
  66. :name => 'New status',
  67. :description => 'New status description'
  68. }
  69. }
  70. )
  71. end
  72. assert_redirected_to :action => 'index'
  73. status = IssueStatus.order('id DESC').first
  74. assert_equal 'New status', status.name
  75. assert_equal 'New status description', status.description
  76. end
  77. def test_create_with_failure
  78. post(
  79. :create,
  80. :params => {
  81. :issue_status => {
  82. :name => ''
  83. }
  84. }
  85. )
  86. assert_response :success
  87. assert_select_error /name cannot be blank/i
  88. end
  89. def test_edit
  90. get(:edit, :params => {:id => '3'})
  91. assert_response :success
  92. assert_select 'input[name=?][value=?]', 'issue_status[name]', 'Resolved'
  93. assert_select 'textarea[name=?]', 'issue_status[description]', 'Description for Resolved issue status'
  94. end
  95. def test_update
  96. put(
  97. :update,
  98. :params => {
  99. :id => '3',
  100. :issue_status => {
  101. :name => 'Renamed status',
  102. :description => 'Renamed status description'
  103. }
  104. }
  105. )
  106. assert_redirected_to :action => 'index'
  107. status = IssueStatus.find(3)
  108. assert_equal 'Renamed status', status.name
  109. assert_equal 'Renamed status description', status.description
  110. end
  111. def test_update_with_failure
  112. put(
  113. :update,
  114. :params => {
  115. :id => '3',
  116. :issue_status => {
  117. :name => ''
  118. }
  119. }
  120. )
  121. assert_response :success
  122. assert_select_error /name cannot be blank/i
  123. end
  124. def test_destroy
  125. Issue.where(:status_id => 1).delete_all
  126. Tracker.where(:default_status_id => 1).delete_all
  127. assert_difference 'IssueStatus.count', -1 do
  128. delete(:destroy, :params => {:id => '1'})
  129. end
  130. assert_redirected_to :action => 'index'
  131. assert_nil IssueStatus.find_by_id(1)
  132. end
  133. def test_destroy_should_block_if_status_is_used_by_issues
  134. assert Issue.where(:status_id => 1).any?
  135. Tracker.where(:default_status_id => 1).delete_all
  136. assert_no_difference 'IssueStatus.count' do
  137. delete(:destroy, :params => {:id => '1'})
  138. end
  139. assert_redirected_to :action => 'index'
  140. assert_not_nil IssueStatus.find_by_id(1)
  141. end
  142. def test_destroy_should_block_if_status_is_used_as_tracker_default_status
  143. Issue.where(:status_id => 1).delete_all
  144. assert Tracker.where(:default_status_id => 1).any?
  145. assert_no_difference 'IssueStatus.count' do
  146. delete(:destroy, :params => {:id => '1'})
  147. end
  148. assert_redirected_to :action => 'index'
  149. assert_not_nil IssueStatus.find_by_id(1)
  150. end
  151. def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_field
  152. with_settings :issue_done_ratio => 'issue_field' do
  153. post :update_issue_done_ratio
  154. assert_match /not updated/, flash[:error].to_s
  155. assert_redirected_to '/issue_statuses'
  156. end
  157. end
  158. def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_status
  159. with_settings :issue_done_ratio => 'issue_status' do
  160. post :update_issue_done_ratio
  161. assert_match /Issue done ratios updated/, flash[:notice].to_s
  162. assert_redirected_to '/issue_statuses'
  163. end
  164. end
  165. end