comparison .svn/pristine/fb/fb08a7fc94c83309a3c9970df3838fd57ed7a246.svn-base @ 1296:038ba2d95de8 redmine-2.2

Fix redmine-2.2 branch update (add missing svn files)
author Chris Cannam
date Fri, 14 Jun 2013 09:05:06 +0100
parents
children
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1296:038ba2d95de8
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 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.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
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_should_contain_reply_field_tags_for_quoting
44 @request.session[:user_id] = 2
45 get :show, :board_id => 1, :id => 1
46 assert_response :success
47
48 # tags required by MessagesController#quote
49 assert_tag 'input', :attributes => {:id => 'message_subject'}
50 assert_tag 'textarea', :attributes => {:id => 'message_content'}
51 assert_tag 'div', :attributes => {:id => 'reply'}
52 end
53
54 def test_show_with_pagination
55 message = Message.find(1)
56 assert_difference 'Message.count', 30 do
57 30.times do
58 message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1)
59 end
60 end
61 get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id
62 assert_response :success
63 assert_template 'show'
64 replies = assigns(:replies)
65 assert_not_nil replies
66 assert !replies.include?(message.children.first(:order => 'id'))
67 assert replies.include?(message.children.last(:order => 'id'))
68 end
69
70 def test_show_with_reply_permission
71 @request.session[:user_id] = 2
72 get :show, :board_id => 1, :id => 1
73 assert_response :success
74 assert_template 'show'
75 assert_tag :div, :attributes => { :id => 'reply' },
76 :descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } }
77 end
78
79 def test_show_message_not_found
80 get :show, :board_id => 1, :id => 99999
81 assert_response 404
82 end
83
84 def test_get_new
85 @request.session[:user_id] = 2
86 get :new, :board_id => 1
87 assert_response :success
88 assert_template 'new'
89 end
90
91 def test_post_new
92 @request.session[:user_id] = 2
93 ActionMailer::Base.deliveries.clear
94
95 with_settings :notified_events => %w(message_posted) do
96 post :new, :board_id => 1,
97 :message => { :subject => 'Test created message',
98 :content => 'Message body'}
99 end
100 message = Message.find_by_subject('Test created message')
101 assert_not_nil message
102 assert_redirected_to "/boards/1/topics/#{message.to_param}"
103 assert_equal 'Message body', message.content
104 assert_equal 2, message.author_id
105 assert_equal 1, message.board_id
106
107 mail = ActionMailer::Base.deliveries.last
108 assert_not_nil mail
109 assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject
110 assert_mail_body_match 'Message body', mail
111 # author
112 assert mail.bcc.include?('jsmith@somenet.foo')
113 # project member
114 assert mail.bcc.include?('dlopper@somenet.foo')
115 end
116
117 def test_get_edit
118 @request.session[:user_id] = 2
119 get :edit, :board_id => 1, :id => 1
120 assert_response :success
121 assert_template 'edit'
122 end
123
124 def test_post_edit
125 @request.session[:user_id] = 2
126 post :edit, :board_id => 1, :id => 1,
127 :message => { :subject => 'New subject',
128 :content => 'New body'}
129 assert_redirected_to '/boards/1/topics/1'
130 message = Message.find(1)
131 assert_equal 'New subject', message.subject
132 assert_equal 'New body', message.content
133 end
134
135 def test_post_edit_sticky_and_locked
136 @request.session[:user_id] = 2
137 post :edit, :board_id => 1, :id => 1,
138 :message => { :subject => 'New subject',
139 :content => 'New body',
140 :locked => '1',
141 :sticky => '1'}
142 assert_redirected_to '/boards/1/topics/1'
143 message = Message.find(1)
144 assert_equal true, message.sticky?
145 assert_equal true, message.locked?
146 end
147
148 def test_post_edit_should_allow_to_change_board
149 @request.session[:user_id] = 2
150 post :edit, :board_id => 1, :id => 1,
151 :message => { :subject => 'New subject',
152 :content => 'New body',
153 :board_id => 2}
154 assert_redirected_to '/boards/2/topics/1'
155 message = Message.find(1)
156 assert_equal Board.find(2), message.board
157 end
158
159 def test_reply
160 @request.session[:user_id] = 2
161 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
162 reply = Message.find(:first, :order => 'id DESC')
163 assert_redirected_to "/boards/1/topics/1?r=#{reply.id}"
164 assert Message.find_by_subject('Test reply')
165 end
166
167 def test_destroy_topic
168 @request.session[:user_id] = 2
169 assert_difference 'Message.count', -3 do
170 post :destroy, :board_id => 1, :id => 1
171 end
172 assert_redirected_to '/projects/ecookbook/boards/1'
173 assert_nil Message.find_by_id(1)
174 end
175
176 def test_destroy_reply
177 @request.session[:user_id] = 2
178 assert_difference 'Message.count', -1 do
179 post :destroy, :board_id => 1, :id => 2
180 end
181 assert_redirected_to '/boards/1/topics/1?r=2'
182 assert_nil Message.find_by_id(2)
183 end
184
185 def test_quote
186 @request.session[:user_id] = 2
187 xhr :get, :quote, :board_id => 1, :id => 3
188 assert_response :success
189 assert_equal 'text/javascript', response.content_type
190 assert_template 'quote'
191 assert_include 'RE: First post', response.body
192 assert_include '> An other reply', response.body
193 end
194
195 def test_preview_new
196 @request.session[:user_id] = 2
197 post :preview,
198 :board_id => 1,
199 :message => {:subject => "", :content => "Previewed text"}
200 assert_response :success
201 assert_template 'common/_preview'
202 end
203
204 def test_preview_edit
205 @request.session[:user_id] = 2
206 post :preview,
207 :id => 4,
208 :board_id => 1,
209 :message => {:subject => "", :content => "Previewed text"}
210 assert_response :success
211 assert_template 'common/_preview'
212 end
213 end