Defect #32664 » 32664_show_errormsg_submitting_reply-v2.patch
app/controllers/messages_controller.rb | ||
---|---|---|
50 | 50 |
offset(@reply_pages.offset). |
51 | 51 |
to_a |
52 | 52 | |
53 |
@reply = Message.new(:subject => "RE: #{@message.subject}") |
|
54 |
render :action => "show", :layout => false if request.xhr? |
|
53 |
@reply = Message.new(:subject => "RE: #{@message.subject}") unless @reply |
|
54 |
if request.xhr? |
|
55 |
render :action => "show", :layout => false |
|
56 |
else |
|
57 |
render :action => "show" |
|
58 |
end |
|
55 | 59 |
end |
56 | 60 | |
57 | 61 |
# Create a new topic |
... | ... | |
77 | 81 |
@reply.author = User.current |
78 | 82 |
@reply.board = @board |
79 | 83 |
@reply.safe_attributes = params[:reply] |
84 |
@reply.save_attachments(params[:attachments]) |
|
80 | 85 |
@topic.children << @reply |
81 | 86 |
if !@reply.new_record? |
82 | 87 |
call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) |
83 |
attachments = Attachment.attach_files(@reply, params[:attachments]) |
|
84 | 88 |
render_attachment_warning_if_needed(@reply) |
89 |
flash[:notice] = l(:notice_successful_update) |
|
90 |
else |
|
91 |
if @reply.errors.include?(:content) && @reply.saved_attachments.blank? |
|
92 |
@reply.errors.delete(:content) |
|
93 |
end |
|
94 |
(show and return) unless @reply.errors.blank? |
|
85 | 95 |
end |
86 |
flash[:notice] = l(:notice_successful_update) |
|
87 | 96 |
redirect_to board_message_path(@board, @topic, :r => @reply) |
88 | 97 |
end |
89 | 98 |
app/views/messages/_form.html.erb | ||
---|---|---|
34 | 34 |
<!--[eoform:message]--> |
35 | 35 | |
36 | 36 |
<p><%= l(:label_attachment_plural) %><br /> |
37 |
<%= render :partial => 'attachments/form', :locals => {:container => @message} %></p>
|
|
37 |
<%= render :partial => 'attachments/form', :locals => {:container => (replying ? @reply : @message)} %></p>
|
|
38 | 38 |
</div> |
app/views/messages/show.html.erb | ||
---|---|---|
23 | 23 |
</div> |
24 | 24 | |
25 | 25 |
<h2><%= avatar(@topic.author) %><%= @topic.subject %></h2> |
26 |
<%= error_messages_for 'reply' %> |
|
26 | 27 | |
27 | 28 |
<div class="message"> |
28 | 29 |
<p><span class="author"><%= authoring @topic.created_on, @topic.author %></span></p> |
... | ... | |
81 | 82 | |
82 | 83 |
<% if !@topic.locked? && authorize_for('messages', 'reply') %> |
83 | 84 |
<p><%= toggle_link l(:button_reply), "reply", :focus => 'message_content' %></p> |
84 |
<div id="reply" style="display:none;">
|
|
85 |
<div id="reply" style="<%= 'display:none;' if @reply.errors.blank? %>">
|
|
85 | 86 |
<%= form_for @reply, :as => :reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true, :id => 'message-form'} do |f| %> |
86 | 87 |
<%= render :partial => 'form', :locals => {:f => f, :replying => true} %> |
87 | 88 |
<%= submit_tag l(:button_submit) %> |
test/functional/messages_controller_test.rb | ||
---|---|---|
20 | 20 |
require File.expand_path('../../test_helper', __FILE__) |
21 | 21 | |
22 | 22 |
class MessagesControllerTest < Redmine::ControllerTest |
23 |
fixtures :projects, :users, :email_addresses, :user_preferences, :members, :member_roles, :roles, :boards, :messages, :enabled_modules |
|
23 |
fixtures :projects, :users, :email_addresses, :user_preferences, :members, :member_roles, :roles, |
|
24 |
:boards, :messages, :attachments, :enabled_modules |
|
24 | 25 | |
25 | 26 |
def setup |
26 | 27 |
User.current = nil |
... | ... | |
217 | 218 | |
218 | 219 |
def test_reply |
219 | 220 |
@request.session[:user_id] = 2 |
220 |
post :reply, :params => { |
|
221 |
assert_difference 'Message.count' do |
|
222 |
post :reply, :params => { |
|
223 |
:board_id => 1, |
|
224 |
:id => 1, |
|
225 |
:reply => { |
|
226 |
:content => 'This is a test reply', |
|
227 |
:subject => 'Test reply' |
|
228 |
} |
|
229 |
} |
|
230 |
end |
|
231 |
reply = Message.order('id DESC').first |
|
232 |
assert_redirected_to "/boards/1/topics/1?r=#{reply.id}" |
|
233 |
assert_equal I18n.t(:notice_successful_update), flash[:notice] |
|
234 |
assert Message.find_by_subject('Test reply') |
|
235 |
end |
|
236 | ||
237 |
def test_reply_with_empty_content_and_none_attachments |
|
238 |
@request.session[:user_id] = 2 |
|
239 |
assert_no_difference 'Message.count' do |
|
240 |
post :reply, :params => { |
|
221 | 241 |
:board_id => 1, |
222 | 242 |
:id => 1, |
223 | 243 |
:reply => { |
224 |
:content => 'This is a test reply',
|
|
244 |
:content => '', |
|
225 | 245 |
:subject => 'Test reply' |
226 | 246 |
} |
227 | 247 |
} |
228 |
reply = Message.order('id DESC').first |
|
229 |
assert_redirected_to "/boards/1/topics/1?r=#{reply.id}" |
|
230 |
assert_equal I18n.t(:notice_successful_update), flash[:notice] |
|
231 |
assert Message.find_by_subject('Test reply') |
|
248 |
end |
|
249 |
assert_redirected_to '/boards/1/topics/1' |
|
250 |
assert_nil flash[:notice] |
|
251 |
end |
|
252 | ||
253 |
def test_reply_with_empty_content_and_any_attachments_should_show_error_message |
|
254 |
set_tmp_attachments_directory |
|
255 |
@request.session[:user_id] = 2 |
|
256 |
assert_no_difference 'Message.count' do |
|
257 |
post :reply, :params => { |
|
258 |
:board_id => 1, |
|
259 |
:id => 1, |
|
260 |
:reply => { |
|
261 |
:content => '', |
|
262 |
:subject => 'Test reply' |
|
263 |
}, |
|
264 |
:attachments => { |
|
265 |
'1' => { |
|
266 |
'file' => uploaded_test_file('testfile.txt', 'text/plain') |
|
267 |
} |
|
268 |
} |
|
269 |
} |
|
270 |
end |
|
271 |
assert_select_error 'Content cannot be blank' |
|
272 |
assert_select 'div#reply' do |
|
273 |
assert_select 'input#message_subject[value=?]', 'Test reply' |
|
274 |
assert_select 'textarea#message_content', :text => '' |
|
275 |
assert_select 'span.attachments_fields' do |
|
276 |
assert_select 'span#attachments_p0 input.filename[value=?]', 'testfile.txt' |
|
277 |
end |
|
278 |
end |
|
232 | 279 |
end |
233 | 280 | |
234 | 281 |
def test_destroy_topic |
- « Previous
- 1
- 2
- 3
- Next »