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.

enumerations_controller_test.rb 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 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 EnumerationsControllerTest < ActionController::TestCase
  19. fixtures :enumerations, :issues, :users
  20. def setup
  21. @request.session[:user_id] = 1 # admin
  22. end
  23. def test_index
  24. get :index
  25. assert_response :success
  26. assert_template 'index'
  27. end
  28. def test_index_should_require_admin
  29. @request.session[:user_id] = nil
  30. get :index
  31. assert_response 302
  32. end
  33. def test_new
  34. get :new, :type => 'IssuePriority'
  35. assert_response :success
  36. assert_template 'new'
  37. assert_kind_of IssuePriority, assigns(:enumeration)
  38. assert_select 'input[name=?][value=?]', 'enumeration[type]', 'IssuePriority'
  39. assert_select 'input[name=?]', 'enumeration[name]'
  40. end
  41. def test_new_with_invalid_type_should_respond_with_404
  42. get :new, :type => 'UnknownType'
  43. assert_response 404
  44. end
  45. def test_create
  46. assert_difference 'IssuePriority.count' do
  47. post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'}
  48. end
  49. assert_redirected_to '/enumerations'
  50. e = IssuePriority.find_by_name('Lowest')
  51. assert_not_nil e
  52. end
  53. def test_create_with_failure
  54. assert_no_difference 'IssuePriority.count' do
  55. post :create, :enumeration => {:type => 'IssuePriority', :name => ''}
  56. end
  57. assert_response :success
  58. assert_template 'new'
  59. end
  60. def test_edit
  61. get :edit, :id => 6
  62. assert_response :success
  63. assert_template 'edit'
  64. assert_select 'input[name=?][value=?]', 'enumeration[name]', 'High'
  65. end
  66. def test_edit_invalid_should_respond_with_404
  67. get :edit, :id => 999
  68. assert_response 404
  69. end
  70. def test_update
  71. assert_no_difference 'IssuePriority.count' do
  72. put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'}
  73. end
  74. assert_redirected_to '/enumerations'
  75. e = IssuePriority.find(6)
  76. assert_equal 'New name', e.name
  77. end
  78. def test_update_with_failure
  79. assert_no_difference 'IssuePriority.count' do
  80. put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''}
  81. end
  82. assert_response :success
  83. assert_template 'edit'
  84. end
  85. def test_destroy_enumeration_not_in_use
  86. assert_difference 'IssuePriority.count', -1 do
  87. delete :destroy, :id => 7
  88. end
  89. assert_redirected_to :controller => 'enumerations', :action => 'index'
  90. assert_nil Enumeration.find_by_id(7)
  91. end
  92. def test_destroy_enumeration_in_use
  93. assert_no_difference 'IssuePriority.count' do
  94. delete :destroy, :id => 4
  95. end
  96. assert_response :success
  97. assert_template 'destroy'
  98. assert_not_nil Enumeration.find_by_id(4)
  99. assert_select 'select[name=reassign_to_id]' do
  100. assert_select 'option[value="6"]', :text => 'High'
  101. end
  102. end
  103. def test_destroy_enumeration_in_use_with_reassignment
  104. issue = Issue.where(:priority_id => 4).first
  105. assert_difference 'IssuePriority.count', -1 do
  106. delete :destroy, :id => 4, :reassign_to_id => 6
  107. end
  108. assert_redirected_to :controller => 'enumerations', :action => 'index'
  109. assert_nil Enumeration.find_by_id(4)
  110. # check that the issue was reassign
  111. assert_equal 6, issue.reload.priority_id
  112. end
  113. def test_destroy_enumeration_in_use_with_blank_reassignment
  114. assert_no_difference 'IssuePriority.count' do
  115. delete :destroy, :id => 4, :reassign_to_id => ''
  116. end
  117. assert_response :success
  118. end
  119. end