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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 BoardsControllerTest < Redmine::ControllerTest
  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, :params => {
  25. :project_id => 1
  26. }
  27. assert_response :success
  28. assert_select 'table.boards'
  29. end
  30. def test_index_not_found
  31. get :index, :params => {
  32. :project_id => 97
  33. }
  34. assert_response 404
  35. end
  36. def test_index_should_show_messages_if_only_one_board
  37. Project.find(1).boards.to_a.slice(1..-1).each(&:destroy)
  38. get :index, :params => {
  39. :project_id => 1
  40. }
  41. assert_response :success
  42. assert_select 'table.boards', 0
  43. assert_select 'table.messages'
  44. end
  45. def test_show
  46. get :show, :params => {
  47. :project_id => 1,
  48. :id => 1
  49. }
  50. assert_response :success
  51. assert_select 'table.messages tbody' do
  52. assert_select 'tr', Board.find(1).topics.count
  53. end
  54. end
  55. def test_show_should_display_sticky_messages_first
  56. Message.update_all(:sticky => 0)
  57. Message.where({:id => 1}).update_all({:sticky => 1})
  58. get :show, :params => {
  59. :project_id => 1,
  60. :id => 1
  61. }
  62. assert_response :success
  63. assert_select 'table.messages tbody' do
  64. # row is here...
  65. assert_select 'tr.sticky'
  66. # ...and in first position
  67. assert_select 'tr.sticky:first-child'
  68. end
  69. end
  70. def test_show_should_display_message_with_last_reply_first
  71. Message.update_all(:sticky => 0)
  72. # Reply to an old topic
  73. old_topic = Message.where(:board_id => 1, :parent_id => nil).order('created_on ASC').first
  74. reply = Message.new(:board_id => 1, :subject => 'New reply', :content => 'New reply', :author_id => 2)
  75. old_topic.children << reply
  76. get :show, :params => {
  77. :project_id => 1,
  78. :id => 1
  79. }
  80. assert_response :success
  81. assert_select 'table.messages tbody' do
  82. assert_select "tr#message-#{old_topic.id}"
  83. assert_select "tr#message-#{old_topic.id}:first-child"
  84. end
  85. end
  86. def test_show_with_permission_should_display_the_new_message_form
  87. @request.session[:user_id] = 2
  88. get :show, :params => {
  89. :project_id => 1,
  90. :id => 1
  91. }
  92. assert_response :success
  93. assert_select 'form#message-form' do
  94. assert_select 'input[name=?]', 'message[subject]'
  95. end
  96. end
  97. def test_show_atom
  98. get :show, :params => {
  99. :project_id => 1,
  100. :id => 1,
  101. :format => 'atom'
  102. }
  103. assert_response :success
  104. assert_select 'feed > entry > title', :text => 'Help: RE: post 2'
  105. end
  106. def test_show_not_found
  107. get :index, :params => {
  108. :project_id => 1,
  109. :id => 97
  110. }
  111. assert_response 404
  112. end
  113. def test_new
  114. @request.session[:user_id] = 2
  115. get :new, :params => {
  116. :project_id => 1
  117. }
  118. assert_response :success
  119. assert_select 'select[name=?]', 'board[parent_id]' do
  120. assert_select 'option', (Project.find(1).boards.size + 1)
  121. assert_select 'option[value=""]'
  122. assert_select 'option[value="1"]', :text => 'Help'
  123. end
  124. # &nbsp; replaced by nokogiri, not easy to test in DOM assertions
  125. assert_not_include '<option value=""></option>', response.body
  126. assert_include '<option value="">&nbsp;</option>', response.body
  127. end
  128. def test_new_without_project_boards
  129. Project.find(1).boards.delete_all
  130. @request.session[:user_id] = 2
  131. get :new, :params => {
  132. :project_id => 1
  133. }
  134. assert_response :success
  135. assert_select 'select[name=?]', 'board[parent_id]', 0
  136. end
  137. def test_create
  138. @request.session[:user_id] = 2
  139. assert_difference 'Board.count' do
  140. post :create, :params => {
  141. :project_id => 1,
  142. :board => {
  143. :name => 'Testing',
  144. :description => 'Testing board creation'
  145. }
  146. }
  147. end
  148. assert_redirected_to '/projects/ecookbook/settings/boards'
  149. board = Board.order('id DESC').first
  150. assert_equal 'Testing', board.name
  151. assert_equal 'Testing board creation', board.description
  152. end
  153. def test_create_with_parent
  154. @request.session[:user_id] = 2
  155. assert_difference 'Board.count' do
  156. post :create, :params => {
  157. :project_id => 1,
  158. :board => {
  159. :name => 'Testing',
  160. :description => 'Testing',
  161. :parent_id => 2
  162. }
  163. }
  164. end
  165. assert_redirected_to '/projects/ecookbook/settings/boards'
  166. board = Board.order('id DESC').first
  167. assert_equal Board.find(2), board.parent
  168. end
  169. def test_create_with_failure
  170. @request.session[:user_id] = 2
  171. assert_no_difference 'Board.count' do
  172. post :create, :params => {
  173. :project_id => 1,
  174. :board => {
  175. :name => '',
  176. :description => 'Testing board creation'
  177. }
  178. }
  179. end
  180. assert_response :success
  181. assert_select_error /Name cannot be blank/
  182. end
  183. def test_edit
  184. @request.session[:user_id] = 2
  185. get :edit, :params => {
  186. :project_id => 1,
  187. :id => 2
  188. }
  189. assert_response :success
  190. assert_select 'input[name=?][value=?]', 'board[name]', 'Discussion'
  191. end
  192. def test_edit_with_parent
  193. board = Board.generate!(:project_id => 1, :parent_id => 2)
  194. @request.session[:user_id] = 2
  195. get :edit, :params => {
  196. :project_id => 1,
  197. :id => board.id
  198. }
  199. assert_response :success
  200. assert_select 'select[name=?]', 'board[parent_id]' do
  201. assert_select 'option[value="2"][selected=selected]'
  202. end
  203. end
  204. def test_update
  205. @request.session[:user_id] = 2
  206. assert_no_difference 'Board.count' do
  207. put :update, :params => {
  208. :project_id => 1,
  209. :id => 2,
  210. :board => {
  211. :name => 'Testing',
  212. :description => 'Testing board update'
  213. }
  214. }
  215. end
  216. assert_redirected_to '/projects/ecookbook/settings/boards'
  217. assert_equal 'Testing', Board.find(2).name
  218. end
  219. def test_update_position
  220. @request.session[:user_id] = 2
  221. put :update, :params => {
  222. :project_id => 1,
  223. :id => 2,
  224. :board => {
  225. :position => 1
  226. }
  227. }
  228. assert_redirected_to '/projects/ecookbook/settings/boards'
  229. board = Board.find(2)
  230. assert_equal 1, board.position
  231. end
  232. def test_update_with_failure
  233. @request.session[:user_id] = 2
  234. put :update, :params => {
  235. :project_id => 1,
  236. :id => 2,
  237. :board => {
  238. :name => '',
  239. :description => 'Testing board update'
  240. }
  241. }
  242. assert_response :success
  243. assert_select_error /Name cannot be blank/
  244. end
  245. def test_destroy
  246. @request.session[:user_id] = 2
  247. assert_difference 'Board.count', -1 do
  248. delete :destroy, :params => {
  249. :project_id => 1,
  250. :id => 2
  251. }
  252. end
  253. assert_redirected_to '/projects/ecookbook/settings/boards'
  254. assert_nil Board.find_by_id(2)
  255. end
  256. end