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

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