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