comparison test/functional/.svn/text-base/messages_controller_test.rb.svn-base @ 0:513646585e45

* Import Redmine trunk SVN rev 3859
author Chris Cannam
date Fri, 23 Jul 2010 15:52:44 +0100
parents
children 94944d00e43c
comparison
equal deleted inserted replaced
-1:000000000000 0:513646585e45
1 # redMine - project management software
2 # Copyright (C) 2006-2007 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
18 require File.dirname(__FILE__) + '/../test_helper'
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
24 class MessagesControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
26
27 def setup
28 @controller = MessagesController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
32 end
33
34 def test_show
35 get :show, :board_id => 1, :id => 1
36 assert_response :success
37 assert_template 'show'
38 assert_not_nil assigns(:board)
39 assert_not_nil assigns(:project)
40 assert_not_nil assigns(:topic)
41 end
42
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', :content => 'Reply body', :author_id => 2, :board_id => 1)
48 end
49 end
50 get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id
51 assert_response :success
52 assert_template 'show'
53 replies = assigns(:replies)
54 assert_not_nil replies
55 assert !replies.include?(message.children.first(:order => 'id'))
56 assert replies.include?(message.children.last(:order => 'id'))
57 end
58
59 def test_show_with_reply_permission
60 @request.session[:user_id] = 2
61 get :show, :board_id => 1, :id => 1
62 assert_response :success
63 assert_template 'show'
64 assert_tag :div, :attributes => { :id => 'reply' },
65 :descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } }
66 end
67
68 def test_show_message_not_found
69 get :show, :board_id => 1, :id => 99999
70 assert_response 404
71 end
72
73 def test_get_new
74 @request.session[:user_id] = 2
75 get :new, :board_id => 1
76 assert_response :success
77 assert_template 'new'
78 end
79
80 def test_post_new
81 @request.session[:user_id] = 2
82 ActionMailer::Base.deliveries.clear
83 Setting.notified_events = ['message_posted']
84
85 post :new, :board_id => 1,
86 :message => { :subject => 'Test created message',
87 :content => 'Message body'}
88 message = Message.find_by_subject('Test created message')
89 assert_not_nil message
90 assert_redirected_to "boards/1/topics/#{message.to_param}"
91 assert_equal 'Message body', message.content
92 assert_equal 2, message.author_id
93 assert_equal 1, message.board_id
94
95 mail = ActionMailer::Base.deliveries.last
96 assert_kind_of TMail::Mail, mail
97 assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject
98 assert mail.body.include?('Message body')
99 # author
100 assert mail.bcc.include?('jsmith@somenet.foo')
101 # project member
102 assert mail.bcc.include?('dlopper@somenet.foo')
103 end
104
105 def test_get_edit
106 @request.session[:user_id] = 2
107 get :edit, :board_id => 1, :id => 1
108 assert_response :success
109 assert_template 'edit'
110 end
111
112 def test_post_edit
113 @request.session[:user_id] = 2
114 post :edit, :board_id => 1, :id => 1,
115 :message => { :subject => 'New subject',
116 :content => 'New body'}
117 assert_redirected_to 'boards/1/topics/1'
118 message = Message.find(1)
119 assert_equal 'New subject', message.subject
120 assert_equal 'New body', message.content
121 end
122
123 def test_reply
124 @request.session[:user_id] = 2
125 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
126 reply = Message.find(:first, :order => 'id DESC')
127 assert_redirected_to "boards/1/topics/1?r=#{reply.id}"
128 assert Message.find_by_subject('Test reply')
129 end
130
131 def test_destroy_topic
132 @request.session[:user_id] = 2
133 post :destroy, :board_id => 1, :id => 1
134 assert_redirected_to 'projects/ecookbook/boards/1'
135 assert_nil Message.find_by_id(1)
136 end
137
138 def test_quote
139 @request.session[:user_id] = 2
140 xhr :get, :quote, :board_id => 1, :id => 3
141 assert_response :success
142 assert_select_rjs :show, 'reply'
143 end
144 end