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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class BoardsControllerTest < Redmine::ControllerTest
  20. fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
  21. def setup
  22. User.current = nil
  23. end
  24. def test_index
  25. get(
  26. :index,
  27. :params => {
  28. :project_id => 1
  29. }
  30. )
  31. assert_response :success
  32. assert_select 'table.boards'
  33. end
  34. def test_index_not_found
  35. get(
  36. :index,
  37. :params => {
  38. :project_id => 97
  39. }
  40. )
  41. assert_response 404
  42. end
  43. def test_index_should_show_messages_if_only_one_board
  44. Project.find(1).boards.to_a.slice(1..-1).each(&:destroy)
  45. get(
  46. :index,
  47. :params => {
  48. :project_id => 1
  49. }
  50. )
  51. assert_response :success
  52. assert_select 'table.boards', 0
  53. assert_select 'table.messages'
  54. end
  55. def test_show
  56. get(
  57. :show,
  58. :params => {
  59. :project_id => 1,
  60. :id => 1
  61. }
  62. )
  63. assert_response :success
  64. assert_select 'table.messages tbody' do
  65. assert_select 'tr', Board.find(1).topics.count
  66. end
  67. end
  68. def test_show_should_display_sticky_messages_first
  69. Message.update_all(:sticky => 0)
  70. Message.where({:id => 1}).update_all({:sticky => 1})
  71. get(
  72. :show,
  73. :params => {
  74. :project_id => 1,
  75. :id => 1
  76. }
  77. )
  78. assert_response :success
  79. assert_select 'table.messages tbody' do
  80. # row is here...
  81. assert_select 'tr.sticky'
  82. # ...and in first position
  83. assert_select 'tr.sticky:first-child'
  84. end
  85. end
  86. def test_show_should_display_message_with_last_reply_first
  87. Message.update_all(:sticky => 0)
  88. # Reply to an old topic
  89. old_topic = Message.where(:board_id => 1, :parent_id => nil).order('created_on ASC').first
  90. reply = Message.new(:board_id => 1, :subject => 'New reply', :content => 'New reply', :author_id => 2)
  91. old_topic.children << reply
  92. get(
  93. :show,
  94. :params => {
  95. :project_id => 1,
  96. :id => 1
  97. }
  98. )
  99. assert_response :success
  100. assert_select 'table.messages tbody' do
  101. assert_select "tr#message-#{old_topic.id}"
  102. assert_select "tr#message-#{old_topic.id}:first-child"
  103. end
  104. end
  105. def test_show_with_permission_should_display_the_new_message_form
  106. @request.session[:user_id] = 2
  107. get(
  108. :show,
  109. :params => {
  110. :project_id => 1,
  111. :id => 1
  112. }
  113. )
  114. assert_response :success
  115. assert_select 'form#message-form' do
  116. assert_select 'input[name=?]', 'message[subject]'
  117. end
  118. end
  119. def test_show_atom
  120. get(
  121. :show,
  122. :params => {
  123. :project_id => 1,
  124. :id => 1,
  125. :format => 'atom'
  126. }
  127. )
  128. assert_response :success
  129. assert_select 'feed > entry > title', :text => 'Help: RE: post 2'
  130. end
  131. def test_show_not_found
  132. get(
  133. :index,
  134. :params => {
  135. :project_id => 1,
  136. :id => 97
  137. }
  138. )
  139. assert_response 404
  140. end
  141. def test_new
  142. @request.session[:user_id] = 2
  143. get(
  144. :new,
  145. :params => {
  146. :project_id => 1
  147. }
  148. )
  149. assert_response :success
  150. assert_select 'select[name=?]', 'board[parent_id]' do
  151. assert_select 'option', (Project.find(1).boards.size + 1)
  152. assert_select 'option[value=""]'
  153. assert_select 'option[value="1"]', :text => 'Help'
  154. end
  155. end
  156. def test_new_without_project_boards
  157. Project.find(1).boards.delete_all
  158. @request.session[:user_id] = 2
  159. get(
  160. :new,
  161. :params => {
  162. :project_id => 1
  163. }
  164. )
  165. assert_response :success
  166. assert_select 'select[name=?]', 'board[parent_id]', 0
  167. end
  168. def test_create
  169. @request.session[:user_id] = 2
  170. assert_difference 'Board.count' do
  171. post(
  172. :create,
  173. :params => {
  174. :project_id => 1,
  175. :board => {
  176. :name => 'Testing',
  177. :description => 'Testing board creation'
  178. }
  179. }
  180. )
  181. end
  182. assert_redirected_to '/projects/ecookbook/settings/boards'
  183. board = Board.order('id DESC').first
  184. assert_equal 'Testing', board.name
  185. assert_equal 'Testing board creation', board.description
  186. end
  187. def test_create_with_parent
  188. @request.session[:user_id] = 2
  189. assert_difference 'Board.count' do
  190. post(
  191. :create,
  192. :params => {
  193. :project_id => 1,
  194. :board => {
  195. :name => 'Testing',
  196. :description => 'Testing',
  197. :parent_id => 2
  198. }
  199. }
  200. )
  201. end
  202. assert_redirected_to '/projects/ecookbook/settings/boards'
  203. board = Board.order('id DESC').first
  204. assert_equal Board.find(2), board.parent
  205. end
  206. def test_create_with_failure
  207. @request.session[:user_id] = 2
  208. assert_no_difference 'Board.count' do
  209. post(
  210. :create,
  211. :params => {
  212. :project_id => 1,
  213. :board => {
  214. :name => '',
  215. :description => 'Testing board creation'
  216. }
  217. }
  218. )
  219. end
  220. assert_response :success
  221. assert_select_error /Name cannot be blank/
  222. end
  223. def test_edit
  224. @request.session[:user_id] = 2
  225. get(
  226. :edit,
  227. :params => {
  228. :project_id => 1,
  229. :id => 2
  230. }
  231. )
  232. assert_response :success
  233. assert_select 'input[name=?][value=?]', 'board[name]', 'Discussion'
  234. end
  235. def test_edit_with_parent
  236. board = Board.generate!(:project_id => 1, :parent_id => 2)
  237. @request.session[:user_id] = 2
  238. get(
  239. :edit,
  240. :params => {
  241. :project_id => 1,
  242. :id => board.id
  243. }
  244. )
  245. assert_response :success
  246. assert_select 'select[name=?]', 'board[parent_id]' do
  247. assert_select 'option[value="2"][selected=selected]'
  248. end
  249. end
  250. def test_update
  251. @request.session[:user_id] = 2
  252. assert_no_difference 'Board.count' do
  253. put(
  254. :update,
  255. :params => {
  256. :project_id => 1,
  257. :id => 2,
  258. :board => {
  259. :name => 'Testing',
  260. :description => 'Testing board update'
  261. }
  262. }
  263. )
  264. end
  265. assert_redirected_to '/projects/ecookbook/settings/boards'
  266. assert_equal 'Testing', Board.find(2).name
  267. end
  268. def test_update_position
  269. @request.session[:user_id] = 2
  270. put(
  271. :update,
  272. :params => {
  273. :project_id => 1,
  274. :id => 2,
  275. :board => {
  276. :position => 1
  277. }
  278. }
  279. )
  280. assert_redirected_to '/projects/ecookbook/settings/boards'
  281. board = Board.find(2)
  282. assert_equal 1, board.position
  283. end
  284. def test_update_with_failure
  285. @request.session[:user_id] = 2
  286. put(
  287. :update,
  288. :params => {
  289. :project_id => 1,
  290. :id => 2,
  291. :board => {
  292. :name => '',
  293. :description => 'Testing board update'
  294. }
  295. }
  296. )
  297. assert_response :success
  298. assert_select_error /Name cannot be blank/
  299. end
  300. def test_destroy
  301. @request.session[:user_id] = 2
  302. assert_difference 'Board.count', -1 do
  303. delete(
  304. :destroy,
  305. :params => {
  306. :project_id => 1,
  307. :id => 2
  308. }
  309. )
  310. end
  311. assert_redirected_to '/projects/ecookbook/settings/boards'
  312. assert_nil Board.find_by_id(2)
  313. end
  314. end