Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

messages_controller_test.rb 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 MessagesControllerTest < Redmine::ControllerTest
  19. fixtures :projects, :users, :email_addresses, :user_preferences, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
  20. def setup
  21. User.current = nil
  22. end
  23. def test_show
  24. get :show, :params => {
  25. :board_id => 1,
  26. :id => 1
  27. }
  28. assert_response :success
  29. assert_select 'h2', :text => 'First post'
  30. end
  31. def test_show_should_contain_reply_field_tags_for_quoting
  32. @request.session[:user_id] = 2
  33. get :show, :params => {
  34. :board_id => 1,
  35. :id => 1
  36. }
  37. assert_response :success
  38. # tags required by MessagesController#quote
  39. assert_select 'input#message_subject'
  40. assert_select 'textarea#message_content'
  41. assert_select 'div#reply'
  42. end
  43. def test_show_with_pagination
  44. message = Message.find(1)
  45. assert_difference 'Message.count', 30 do
  46. 30.times do
  47. message.children << Message.new(:subject => 'Reply',
  48. :content => 'Reply body',
  49. :author_id => 2,
  50. :board_id => 1)
  51. end
  52. end
  53. reply_ids = message.children.map(&:id).sort
  54. get :show, :params => {
  55. :board_id => 1,
  56. :id => 1,
  57. :r => reply_ids.last
  58. }
  59. assert_response :success
  60. assert_select 'a[href=?]', "/boards/1/topics/1?r=#{reply_ids.last}#message-#{reply_ids.last}"
  61. assert_select 'a[href=?]', "/boards/1/topics/1?r=#{reply_ids.first}#message-#{reply_ids.first}", 0
  62. end
  63. def test_show_with_reply_permission
  64. @request.session[:user_id] = 2
  65. get :show, :params => {
  66. :board_id => 1,
  67. :id => 1
  68. }
  69. assert_response :success
  70. assert_select 'div#reply textarea#message_content'
  71. end
  72. def test_show_message_not_found
  73. get :show, :params => {
  74. :board_id => 1,
  75. :id => 99999
  76. }
  77. assert_response 404
  78. end
  79. def test_show_message_from_invalid_board_should_respond_with_404
  80. get :show, :params => {
  81. :board_id => 999,
  82. :id => 1
  83. }
  84. assert_response 404
  85. end
  86. def test_get_new
  87. @request.session[:user_id] = 2
  88. get :new, :params => {
  89. :board_id => 1
  90. }
  91. assert_response :success
  92. assert_select 'input[name=?]', 'message[subject]'
  93. end
  94. def test_get_new_with_invalid_board
  95. @request.session[:user_id] = 2
  96. get :new, :params => {
  97. :board_id => 99
  98. }
  99. assert_response 404
  100. end
  101. def test_post_new
  102. @request.session[:user_id] = 2
  103. ActionMailer::Base.deliveries.clear
  104. with_settings :notified_events => %w(message_posted) do
  105. post :new, :params => {
  106. :board_id => 1,
  107. :message => {
  108. :subject => 'Test created message',
  109. :content => 'Message body'
  110. }
  111. }
  112. end
  113. message = Message.find_by_subject('Test created message')
  114. assert_not_nil message
  115. assert_redirected_to "/boards/1/topics/#{message.to_param}"
  116. assert_equal 'Message body', message.content
  117. assert_equal 2, message.author_id
  118. assert_equal 1, message.board_id
  119. mails = ActionMailer::Base.deliveries
  120. assert_not_empty mails
  121. mails.each do |mail|
  122. assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject
  123. assert_mail_body_match 'Message body', mail
  124. end
  125. # author
  126. assert_equal ['jsmith@somenet.foo'], mails[0].bcc
  127. # project member
  128. assert_equal ['dlopper@somenet.foo'], mails[1].bcc
  129. end
  130. def test_get_edit
  131. @request.session[:user_id] = 2
  132. get :edit, :params => {
  133. :board_id => 1,
  134. :id => 1
  135. }
  136. assert_response :success
  137. assert_select 'input[name=?][value=?]', 'message[subject]', 'First post'
  138. end
  139. def test_post_edit
  140. @request.session[:user_id] = 2
  141. post :edit, :params => {
  142. :board_id => 1,
  143. :id => 1,
  144. :message => {
  145. :subject => 'New subject',
  146. :content => 'New body'
  147. }
  148. }
  149. assert_redirected_to '/boards/1/topics/1'
  150. message = Message.find(1)
  151. assert_equal 'New subject', message.subject
  152. assert_equal 'New body', message.content
  153. end
  154. def test_post_edit_sticky_and_locked
  155. @request.session[:user_id] = 2
  156. post :edit, :params => {
  157. :board_id => 1,
  158. :id => 1,
  159. :message => {
  160. :subject => 'New subject',
  161. :content => 'New body',
  162. :locked => '1',
  163. :sticky => '1'
  164. }
  165. }
  166. assert_redirected_to '/boards/1/topics/1'
  167. message = Message.find(1)
  168. assert_equal true, message.sticky?
  169. assert_equal true, message.locked?
  170. end
  171. def test_post_edit_should_allow_to_change_board
  172. @request.session[:user_id] = 2
  173. post :edit, :params => {
  174. :board_id => 1,
  175. :id => 1,
  176. :message => {
  177. :subject => 'New subject',
  178. :content => 'New body',
  179. :board_id => 2
  180. }
  181. }
  182. assert_redirected_to '/boards/2/topics/1'
  183. message = Message.find(1)
  184. assert_equal Board.find(2), message.board
  185. end
  186. def test_reply
  187. @request.session[:user_id] = 2
  188. post :reply, :params => {
  189. :board_id => 1,
  190. :id => 1,
  191. :reply => {
  192. :content => 'This is a test reply',
  193. :subject => 'Test reply'
  194. }
  195. }
  196. reply = Message.order('id DESC').first
  197. assert_redirected_to "/boards/1/topics/1?r=#{reply.id}"
  198. assert Message.find_by_subject('Test reply')
  199. end
  200. def test_destroy_topic
  201. @request.session[:user_id] = 2
  202. assert_difference 'Message.count', -3 do
  203. post :destroy, :params => {
  204. :board_id => 1,
  205. :id => 1
  206. }
  207. end
  208. assert_redirected_to '/projects/ecookbook/boards/1'
  209. assert_nil Message.find_by_id(1)
  210. end
  211. def test_destroy_reply
  212. @request.session[:user_id] = 2
  213. assert_difference 'Message.count', -1 do
  214. post :destroy, :params => {
  215. :board_id => 1,
  216. :id => 2
  217. }
  218. end
  219. assert_redirected_to '/boards/1/topics/1?r=2'
  220. assert_nil Message.find_by_id(2)
  221. end
  222. def test_quote
  223. @request.session[:user_id] = 2
  224. get :quote, :params => {
  225. :board_id => 1,
  226. :id => 3
  227. },
  228. :xhr => true
  229. assert_response :success
  230. assert_equal 'text/javascript', response.content_type
  231. assert_include 'RE: First post', response.body
  232. assert_include '> An other reply', response.body
  233. end
  234. def test_preview_new
  235. @request.session[:user_id] = 2
  236. post :preview, :params => {
  237. :board_id => 1,
  238. :message => {
  239. :subject => ""
  240. },
  241. :text => "Previewed text"
  242. }
  243. assert_response :success
  244. assert_include 'Previewed text', response.body
  245. end
  246. def test_preview_edit
  247. @request.session[:user_id] = 2
  248. post :preview, :params => {
  249. :id => 4,
  250. :board_id => 1,
  251. :message => {
  252. :subject => "",
  253. },
  254. :text => "Previewed text"
  255. }
  256. assert_response :success
  257. assert_include 'Previewed text', response.body
  258. end
  259. end