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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 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_new
  29. get :new, :type => 'IssuePriority'
  30. assert_response :success
  31. assert_template 'new'
  32. assert_kind_of IssuePriority, assigns(:enumeration)
  33. assert_tag 'input', :attributes => {:name => 'enumeration[type]', :value => 'IssuePriority'}
  34. assert_tag 'input', :attributes => {:name => 'enumeration[name]'}
  35. end
  36. def test_new_with_invalid_type_should_respond_with_404
  37. get :new, :type => 'UnknownType'
  38. assert_response 404
  39. end
  40. def test_create
  41. assert_difference 'IssuePriority.count' do
  42. post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'}
  43. end
  44. assert_redirected_to '/enumerations?type=IssuePriority'
  45. e = IssuePriority.find_by_name('Lowest')
  46. assert_not_nil e
  47. end
  48. def test_create_with_failure
  49. assert_no_difference 'IssuePriority.count' do
  50. post :create, :enumeration => {:type => 'IssuePriority', :name => ''}
  51. end
  52. assert_response :success
  53. assert_template 'new'
  54. end
  55. def test_edit
  56. get :edit, :id => 6
  57. assert_response :success
  58. assert_template 'edit'
  59. assert_tag 'input', :attributes => {:name => 'enumeration[name]', :value => 'High'}
  60. end
  61. def test_edit_invalid_should_respond_with_404
  62. get :edit, :id => 999
  63. assert_response 404
  64. end
  65. def test_update
  66. assert_no_difference 'IssuePriority.count' do
  67. put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'}
  68. end
  69. assert_redirected_to '/enumerations?type=IssuePriority'
  70. e = IssuePriority.find(6)
  71. assert_equal 'New name', e.name
  72. end
  73. def test_update_with_failure
  74. assert_no_difference 'IssuePriority.count' do
  75. put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''}
  76. end
  77. assert_response :success
  78. assert_template 'edit'
  79. end
  80. def test_destroy_enumeration_not_in_use
  81. assert_difference 'IssuePriority.count', -1 do
  82. delete :destroy, :id => 7
  83. end
  84. assert_redirected_to :controller => 'enumerations', :action => 'index'
  85. assert_nil Enumeration.find_by_id(7)
  86. end
  87. def test_destroy_enumeration_in_use
  88. assert_no_difference 'IssuePriority.count' do
  89. delete :destroy, :id => 4
  90. end
  91. assert_response :success
  92. assert_template 'destroy'
  93. assert_not_nil Enumeration.find_by_id(4)
  94. assert_select 'select[name=reassign_to_id]' do
  95. assert_select 'option[value=6]', :text => 'High'
  96. end
  97. end
  98. def test_destroy_enumeration_in_use_with_reassignment
  99. issue = Issue.find(:first, :conditions => {:priority_id => 4})
  100. assert_difference 'IssuePriority.count', -1 do
  101. delete :destroy, :id => 4, :reassign_to_id => 6
  102. end
  103. assert_redirected_to :controller => 'enumerations', :action => 'index'
  104. assert_nil Enumeration.find_by_id(4)
  105. # check that the issue was reassign
  106. assert_equal 6, issue.reload.priority_id
  107. end
  108. end