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.

boards_controller_test.rb 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 BoardsControllerTest < ActionController::TestCase
  19. fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
  20. def setup
  21. User.current = nil
  22. end
  23. def test_index
  24. get :index, :project_id => 1
  25. assert_response :success
  26. assert_template 'index'
  27. assert_not_nil assigns(:boards)
  28. assert_not_nil assigns(:project)
  29. end
  30. def test_index_not_found
  31. get :index, :project_id => 97
  32. assert_response 404
  33. end
  34. def test_index_should_show_messages_if_only_one_board
  35. Project.find(1).boards.slice(1..-1).each(&:destroy)
  36. get :index, :project_id => 1
  37. assert_response :success
  38. assert_template 'show'
  39. assert_not_nil assigns(:topics)
  40. end
  41. def test_show
  42. get :show, :project_id => 1, :id => 1
  43. assert_response :success
  44. assert_template 'show'
  45. assert_not_nil assigns(:board)
  46. assert_not_nil assigns(:project)
  47. assert_not_nil assigns(:topics)
  48. end
  49. def test_show_with_permission_should_display_the_new_message_form
  50. @request.session[:user_id] = 2
  51. get :show, :project_id => 1, :id => 1
  52. assert_response :success
  53. assert_template 'show'
  54. assert_tag 'form', :attributes => {:id => 'message-form'}
  55. assert_tag 'input', :attributes => {:name => 'message[subject]'}
  56. end
  57. def test_show_atom
  58. get :show, :project_id => 1, :id => 1, :format => 'atom'
  59. assert_response :success
  60. assert_template 'common/feed'
  61. assert_not_nil assigns(:board)
  62. assert_not_nil assigns(:project)
  63. assert_not_nil assigns(:messages)
  64. end
  65. def test_show_not_found
  66. get :index, :project_id => 1, :id => 97
  67. assert_response 404
  68. end
  69. def test_new
  70. @request.session[:user_id] = 2
  71. get :new, :project_id => 1
  72. assert_response :success
  73. assert_template 'new'
  74. end
  75. def test_create
  76. @request.session[:user_id] = 2
  77. assert_difference 'Board.count' do
  78. post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
  79. end
  80. assert_redirected_to '/projects/ecookbook/settings/boards'
  81. board = Board.first(:order => 'id DESC')
  82. assert_equal 'Testing', board.name
  83. assert_equal 'Testing board creation', board.description
  84. end
  85. def test_create_with_failure
  86. @request.session[:user_id] = 2
  87. assert_no_difference 'Board.count' do
  88. post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
  89. end
  90. assert_response :success
  91. assert_template 'new'
  92. end
  93. def test_edit
  94. @request.session[:user_id] = 2
  95. get :edit, :project_id => 1, :id => 2
  96. assert_response :success
  97. assert_template 'edit'
  98. end
  99. def test_update
  100. @request.session[:user_id] = 2
  101. assert_no_difference 'Board.count' do
  102. put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
  103. end
  104. assert_redirected_to '/projects/ecookbook/settings/boards'
  105. assert_equal 'Testing', Board.find(2).name
  106. end
  107. def test_update_position
  108. @request.session[:user_id] = 2
  109. put :update, :project_id => 1, :id => 2, :board => { :move_to => 'highest'}
  110. assert_redirected_to '/projects/ecookbook/settings/boards'
  111. board = Board.find(2)
  112. assert_equal 1, board.position
  113. end
  114. def test_update_with_failure
  115. @request.session[:user_id] = 2
  116. put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
  117. assert_response :success
  118. assert_template 'edit'
  119. end
  120. def test_destroy
  121. @request.session[:user_id] = 2
  122. assert_difference 'Board.count', -1 do
  123. delete :destroy, :project_id => 1, :id => 2
  124. end
  125. assert_redirected_to '/projects/ecookbook/settings/boards'
  126. assert_nil Board.find_by_id(2)
  127. end
  128. end