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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2016 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, :issue_status => {:name => 'New status'}
  47. end
  48. assert_redirected_to :action => 'index'
  49. status = IssueStatus.order('id DESC').first
  50. assert_equal 'New status', status.name
  51. end
  52. def test_create_with_failure
  53. post :create, :issue_status => {:name => ''}
  54. assert_response :success
  55. assert_select_error /name cannot be blank/i
  56. end
  57. def test_edit
  58. get :edit, :id => '3'
  59. assert_response :success
  60. assert_select 'input[name=?][value=?]', 'issue_status[name]', 'Resolved'
  61. end
  62. def test_update
  63. put :update, :id => '3', :issue_status => {:name => 'Renamed status'}
  64. assert_redirected_to :action => 'index'
  65. status = IssueStatus.find(3)
  66. assert_equal 'Renamed status', status.name
  67. end
  68. def test_update_with_failure
  69. put :update, :id => '3', :issue_status => {:name => ''}
  70. assert_response :success
  71. assert_select_error /name cannot be blank/i
  72. end
  73. def test_destroy
  74. Issue.where(:status_id => 1).delete_all
  75. Tracker.where(:default_status_id => 1).delete_all
  76. assert_difference 'IssueStatus.count', -1 do
  77. delete :destroy, :id => '1'
  78. end
  79. assert_redirected_to :action => 'index'
  80. assert_nil IssueStatus.find_by_id(1)
  81. end
  82. def test_destroy_should_block_if_status_is_used_by_issues
  83. assert Issue.where(:status_id => 1).any?
  84. Tracker.where(:default_status_id => 1).delete_all
  85. assert_no_difference 'IssueStatus.count' do
  86. delete :destroy, :id => '1'
  87. end
  88. assert_redirected_to :action => 'index'
  89. assert_not_nil IssueStatus.find_by_id(1)
  90. end
  91. def test_destroy_should_block_if_status_is_used_as_tracker_default_status
  92. Issue.where(:status_id => 1).delete_all
  93. assert Tracker.where(:default_status_id => 1).any?
  94. assert_no_difference 'IssueStatus.count' do
  95. delete :destroy, :id => '1'
  96. end
  97. assert_redirected_to :action => 'index'
  98. assert_not_nil IssueStatus.find_by_id(1)
  99. end
  100. def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_field
  101. with_settings :issue_done_ratio => 'issue_field' do
  102. post :update_issue_done_ratio
  103. assert_match /not updated/, flash[:error].to_s
  104. assert_redirected_to '/issue_statuses'
  105. end
  106. end
  107. def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_status
  108. with_settings :issue_done_ratio => 'issue_status' do
  109. post :update_issue_done_ratio
  110. assert_match /Issue done ratios updated/, flash[:notice].to_s
  111. assert_redirected_to '/issue_statuses'
  112. end
  113. end
  114. end