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_categories_controller_test.rb 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 IssueCategoriesControllerTest < Redmine::ControllerTest
  19. fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories,
  20. :issues
  21. def setup
  22. User.current = nil
  23. @request.session[:user_id] = 2
  24. end
  25. def test_new
  26. @request.session[:user_id] = 2 # manager
  27. get :new, :params => {
  28. :project_id => '1'
  29. }
  30. assert_response :success
  31. assert_select 'input[name=?]', 'issue_category[name]'
  32. end
  33. def test_new_from_issue_form
  34. @request.session[:user_id] = 2 # manager
  35. get :new, :params => {
  36. :project_id => '1'
  37. },
  38. :xhr => true
  39. assert_response :success
  40. assert_equal 'text/javascript', response.content_type
  41. end
  42. def test_create
  43. @request.session[:user_id] = 2 # manager
  44. assert_difference 'IssueCategory.count' do
  45. post :create, :params => {
  46. :project_id => '1',
  47. :issue_category => {
  48. :name => 'New category'
  49. }
  50. }
  51. end
  52. assert_redirected_to '/projects/ecookbook/settings/categories'
  53. category = IssueCategory.find_by_name('New category')
  54. assert_not_nil category
  55. assert_equal 1, category.project_id
  56. end
  57. def test_create_failure
  58. @request.session[:user_id] = 2
  59. post :create, :params => {
  60. :project_id => '1',
  61. :issue_category => {
  62. :name => ''
  63. }
  64. }
  65. assert_response :success
  66. assert_select_error /Name cannot be blank/i
  67. end
  68. def test_create_from_issue_form
  69. @request.session[:user_id] = 2 # manager
  70. assert_difference 'IssueCategory.count' do
  71. post :create, :params => {
  72. :project_id => '1',
  73. :issue_category => {
  74. :name => 'New category'
  75. }
  76. },
  77. :xhr => true
  78. end
  79. category = IssueCategory.order('id DESC').first
  80. assert_equal 'New category', category.name
  81. assert_response :success
  82. assert_equal 'text/javascript', response.content_type
  83. end
  84. def test_create_from_issue_form_with_failure
  85. @request.session[:user_id] = 2 # manager
  86. assert_no_difference 'IssueCategory.count' do
  87. post :create, :params => {
  88. :project_id => '1',
  89. :issue_category => {
  90. :name => ''
  91. }
  92. },
  93. :xhr => true
  94. end
  95. assert_response :success
  96. assert_equal 'text/javascript', response.content_type
  97. assert_include 'Name cannot be blank', response.body
  98. end
  99. def test_edit
  100. @request.session[:user_id] = 2
  101. get :edit, :params => {
  102. :id => 2
  103. }
  104. assert_response :success
  105. assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes'
  106. end
  107. def test_update
  108. assert_no_difference 'IssueCategory.count' do
  109. put :update, :params => {
  110. :id => 2,
  111. :issue_category => {
  112. :name => 'Testing'
  113. }
  114. }
  115. end
  116. assert_redirected_to '/projects/ecookbook/settings/categories'
  117. assert_equal 'Testing', IssueCategory.find(2).name
  118. end
  119. def test_update_failure
  120. put :update, :params => {
  121. :id => 2,
  122. :issue_category => {
  123. :name => ''
  124. }
  125. }
  126. assert_response :success
  127. assert_select_error /Name cannot be blank/i
  128. end
  129. def test_update_not_found
  130. put :update, :params => {
  131. :id => 97,
  132. :issue_category => {
  133. :name => 'Testing'
  134. }
  135. }
  136. assert_response 404
  137. end
  138. def test_destroy_category_not_in_use
  139. delete :destroy, :params => {
  140. :id => 2
  141. }
  142. assert_redirected_to '/projects/ecookbook/settings/categories'
  143. assert_nil IssueCategory.find_by_id(2)
  144. end
  145. def test_destroy_category_in_use
  146. delete :destroy, :params => {
  147. :id => 1
  148. }
  149. assert_response :success
  150. assert_not_nil IssueCategory.find_by_id(1)
  151. assert_select 'select[name=?]', 'reassign_to_id'
  152. end
  153. def test_destroy_category_in_use_with_reassignment
  154. issue = Issue.where(:category_id => 1).first
  155. delete :destroy, :params => {
  156. :id => 1,
  157. :todo => 'reassign',
  158. :reassign_to_id => 2
  159. }
  160. assert_redirected_to '/projects/ecookbook/settings/categories'
  161. assert_nil IssueCategory.find_by_id(1)
  162. # check that the issue was reassign
  163. assert_equal 2, issue.reload.category_id
  164. end
  165. def test_destroy_category_in_use_without_reassignment
  166. issue = Issue.where(:category_id => 1).first
  167. delete :destroy, :params => {
  168. :id => 1,
  169. :todo => 'nullify'
  170. }
  171. assert_redirected_to '/projects/ecookbook/settings/categories'
  172. assert_nil IssueCategory.find_by_id(1)
  173. # check that the issue category was nullified
  174. assert_nil issue.reload.category_id
  175. end
  176. end