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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 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_should_display_sticky_messages_first
  50. Message.update_all(:sticky => 0)
  51. Message.where({:id => 1}).update_all({:sticky => 1})
  52. get :show, :project_id => 1, :id => 1
  53. assert_response :success
  54. topics = assigns(:topics)
  55. assert_not_nil topics
  56. assert topics.size > 1, "topics size was #{topics.size}"
  57. assert topics.first.sticky?
  58. assert topics.first.updated_on < topics.second.updated_on
  59. end
  60. def test_show_should_display_message_with_last_reply_first
  61. Message.update_all(:sticky => 0)
  62. # Reply to an old topic
  63. old_topic = Message.where(:board_id => 1, :parent_id => nil).order('created_on ASC').first
  64. reply = Message.new(:board_id => 1, :subject => 'New reply', :content => 'New reply', :author_id => 2)
  65. old_topic.children << reply
  66. get :show, :project_id => 1, :id => 1
  67. assert_response :success
  68. topics = assigns(:topics)
  69. assert_not_nil topics
  70. assert_equal old_topic, topics.first
  71. end
  72. def test_show_with_permission_should_display_the_new_message_form
  73. @request.session[:user_id] = 2
  74. get :show, :project_id => 1, :id => 1
  75. assert_response :success
  76. assert_template 'show'
  77. assert_select 'form#message-form' do
  78. assert_select 'input[name=?]', 'message[subject]'
  79. end
  80. end
  81. def test_show_atom
  82. get :show, :project_id => 1, :id => 1, :format => 'atom'
  83. assert_response :success
  84. assert_template 'common/feed'
  85. assert_not_nil assigns(:board)
  86. assert_not_nil assigns(:project)
  87. assert_not_nil assigns(:messages)
  88. end
  89. def test_show_not_found
  90. get :index, :project_id => 1, :id => 97
  91. assert_response 404
  92. end
  93. def test_new
  94. @request.session[:user_id] = 2
  95. get :new, :project_id => 1
  96. assert_response :success
  97. assert_template 'new'
  98. assert_select 'select[name=?]', 'board[parent_id]' do
  99. assert_select 'option', (Project.find(1).boards.size + 1)
  100. assert_select 'option[value=""]'
  101. assert_select 'option[value="1"]', :text => 'Help'
  102. end
  103. # &nbsp; replaced by nokogiri, not easy to test in DOM assertions
  104. assert_not_include '<option value=""></option>', response.body
  105. assert_include '<option value="">&nbsp;</option>', response.body
  106. end
  107. def test_new_without_project_boards
  108. Project.find(1).boards.delete_all
  109. @request.session[:user_id] = 2
  110. get :new, :project_id => 1
  111. assert_response :success
  112. assert_template 'new'
  113. assert_select 'select[name=?]', 'board[parent_id]', 0
  114. end
  115. def test_create
  116. @request.session[:user_id] = 2
  117. assert_difference 'Board.count' do
  118. post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
  119. end
  120. assert_redirected_to '/projects/ecookbook/settings/boards'
  121. board = Board.order('id DESC').first
  122. assert_equal 'Testing', board.name
  123. assert_equal 'Testing board creation', board.description
  124. end
  125. def test_create_with_parent
  126. @request.session[:user_id] = 2
  127. assert_difference 'Board.count' do
  128. post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing', :parent_id => 2}
  129. end
  130. assert_redirected_to '/projects/ecookbook/settings/boards'
  131. board = Board.order('id DESC').first
  132. assert_equal Board.find(2), board.parent
  133. end
  134. def test_create_with_failure
  135. @request.session[:user_id] = 2
  136. assert_no_difference 'Board.count' do
  137. post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
  138. end
  139. assert_response :success
  140. assert_template 'new'
  141. end
  142. def test_edit
  143. @request.session[:user_id] = 2
  144. get :edit, :project_id => 1, :id => 2
  145. assert_response :success
  146. assert_template 'edit'
  147. end
  148. def test_edit_with_parent
  149. board = Board.generate!(:project_id => 1, :parent_id => 2)
  150. @request.session[:user_id] = 2
  151. get :edit, :project_id => 1, :id => board.id
  152. assert_response :success
  153. assert_template 'edit'
  154. assert_select 'select[name=?]', 'board[parent_id]' do
  155. assert_select 'option[value="2"][selected=selected]'
  156. end
  157. end
  158. def test_update
  159. @request.session[:user_id] = 2
  160. assert_no_difference 'Board.count' do
  161. put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
  162. end
  163. assert_redirected_to '/projects/ecookbook/settings/boards'
  164. assert_equal 'Testing', Board.find(2).name
  165. end
  166. def test_update_position
  167. @request.session[:user_id] = 2
  168. put :update, :project_id => 1, :id => 2, :board => { :move_to => 'highest'}
  169. assert_redirected_to '/projects/ecookbook/settings/boards'
  170. board = Board.find(2)
  171. assert_equal 1, board.position
  172. end
  173. def test_update_with_failure
  174. @request.session[:user_id] = 2
  175. put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
  176. assert_response :success
  177. assert_template 'edit'
  178. end
  179. def test_destroy
  180. @request.session[:user_id] = 2
  181. assert_difference 'Board.count', -1 do
  182. delete :destroy, :project_id => 1, :id => 2
  183. end
  184. assert_redirected_to '/projects/ecookbook/settings/boards'
  185. assert_nil Board.find_by_id(2)
  186. end
  187. end