comparison test/functional/messages_controller_test.rb @ 1526:404aa68d4227

Merge from live branch
author Chris Cannam
date Thu, 11 Sep 2014 12:46:20 +0100
parents dffacf8a6908
children
comparison
equal deleted inserted replaced
1493:a5f2bdf3b486 1526:404aa68d4227
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
14 # You should have received a copy of the GNU General Public License 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 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. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.expand_path('../../test_helper', __FILE__) 18 require File.expand_path('../../test_helper', __FILE__)
19 require 'messages_controller'
20
21 # Re-raise errors caught by the controller.
22 class MessagesController; def rescue_action(e) raise e end; end
23 19
24 class MessagesControllerTest < ActionController::TestCase 20 class MessagesControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules 21 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
26 22
27 def setup 23 def setup
28 @controller = MessagesController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
31 User.current = nil 24 User.current = nil
32 end 25 end
33 26
34 def test_show 27 def test_show
35 get :show, :board_id => 1, :id => 1 28 get :show, :board_id => 1, :id => 1
53 46
54 def test_show_with_pagination 47 def test_show_with_pagination
55 message = Message.find(1) 48 message = Message.find(1)
56 assert_difference 'Message.count', 30 do 49 assert_difference 'Message.count', 30 do
57 30.times do 50 30.times do
58 message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1) 51 message.children << Message.new(:subject => 'Reply',
52 :content => 'Reply body',
53 :author_id => 2,
54 :board_id => 1)
59 end 55 end
60 end 56 end
61 get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id 57 get :show, :board_id => 1, :id => 1, :r => message.children.order('id').last.id
62 assert_response :success 58 assert_response :success
63 assert_template 'show' 59 assert_template 'show'
64 replies = assigns(:replies) 60 replies = assigns(:replies)
65 assert_not_nil replies 61 assert_not_nil replies
66 assert !replies.include?(message.children.first(:order => 'id')) 62 assert !replies.include?(message.children.order('id').first)
67 assert replies.include?(message.children.last(:order => 'id')) 63 assert replies.include?(message.children.order('id').last)
68 end 64 end
69 65
70 def test_show_with_reply_permission 66 def test_show_with_reply_permission
71 @request.session[:user_id] = 2 67 @request.session[:user_id] = 2
72 get :show, :board_id => 1, :id => 1 68 get :show, :board_id => 1, :id => 1
89 def test_get_new 85 def test_get_new
90 @request.session[:user_id] = 2 86 @request.session[:user_id] = 2
91 get :new, :board_id => 1 87 get :new, :board_id => 1
92 assert_response :success 88 assert_response :success
93 assert_template 'new' 89 assert_template 'new'
90 end
91
92 def test_get_new_with_invalid_board
93 @request.session[:user_id] = 2
94 get :new, :board_id => 99
95 assert_response 404
94 end 96 end
95 97
96 def test_post_new 98 def test_post_new
97 @request.session[:user_id] = 2 99 @request.session[:user_id] = 2
98 ActionMailer::Base.deliveries.clear 100 ActionMailer::Base.deliveries.clear
162 end 164 end
163 165
164 def test_reply 166 def test_reply
165 @request.session[:user_id] = 2 167 @request.session[:user_id] = 2
166 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' } 168 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
167 reply = Message.find(:first, :order => 'id DESC') 169 reply = Message.order('id DESC').first
168 assert_redirected_to "/boards/1/topics/1?r=#{reply.id}" 170 assert_redirected_to "/boards/1/topics/1?r=#{reply.id}"
169 assert Message.find_by_subject('Test reply') 171 assert Message.find_by_subject('Test reply')
170 end 172 end
171 173
172 def test_destroy_topic 174 def test_destroy_topic