Project

General

Profile

Defect #32664 » 32664_show_errormsg_submitting_reply-v2.patch

Yuichi HARADA, 2020-01-16 06:04

View differences:

app/controllers/messages_controller.rb
offset(@reply_pages.offset).
to_a
@reply = Message.new(:subject => "RE: #{@message.subject}")
render :action => "show", :layout => false if request.xhr?
@reply = Message.new(:subject => "RE: #{@message.subject}") unless @reply
if request.xhr?
render :action => "show", :layout => false
else
render :action => "show"
end
end
# Create a new topic
......
@reply.author = User.current
@reply.board = @board
@reply.safe_attributes = params[:reply]
@reply.save_attachments(params[:attachments])
@topic.children << @reply
if !@reply.new_record?
call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
attachments = Attachment.attach_files(@reply, params[:attachments])
render_attachment_warning_if_needed(@reply)
flash[:notice] = l(:notice_successful_update)
else
if @reply.errors.include?(:content) && @reply.saved_attachments.blank?
@reply.errors.delete(:content)
end
(show and return) unless @reply.errors.blank?
end
flash[:notice] = l(:notice_successful_update)
redirect_to board_message_path(@board, @topic, :r => @reply)
end
app/views/messages/_form.html.erb
<!--[eoform:message]-->
<p><%= l(:label_attachment_plural) %><br />
<%= render :partial => 'attachments/form', :locals => {:container => @message} %></p>
<%= render :partial => 'attachments/form', :locals => {:container => (replying ? @reply : @message)} %></p>
</div>
app/views/messages/show.html.erb
</div>
<h2><%= avatar(@topic.author) %><%= @topic.subject %></h2>
<%= error_messages_for 'reply' %>
<div class="message">
<p><span class="author"><%= authoring @topic.created_on, @topic.author %></span></p>
......
<% if !@topic.locked? && authorize_for('messages', 'reply') %>
<p><%= toggle_link l(:button_reply), "reply", :focus => 'message_content' %></p>
<div id="reply" style="display:none;">
<div id="reply" style="<%= 'display:none;' if @reply.errors.blank? %>">
<%= form_for @reply, :as => :reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true, :id => 'message-form'} do |f| %>
<%= render :partial => 'form', :locals => {:f => f, :replying => true} %>
<%= submit_tag l(:button_submit) %>
test/functional/messages_controller_test.rb
require File.expand_path('../../test_helper', __FILE__)
class MessagesControllerTest < Redmine::ControllerTest
fixtures :projects, :users, :email_addresses, :user_preferences, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
fixtures :projects, :users, :email_addresses, :user_preferences, :members, :member_roles, :roles,
:boards, :messages, :attachments, :enabled_modules
def setup
User.current = nil
......
def test_reply
@request.session[:user_id] = 2
post :reply, :params => {
assert_difference 'Message.count' do
post :reply, :params => {
:board_id => 1,
:id => 1,
:reply => {
:content => 'This is a test reply',
:subject => 'Test reply'
}
}
end
reply = Message.order('id DESC').first
assert_redirected_to "/boards/1/topics/1?r=#{reply.id}"
assert_equal I18n.t(:notice_successful_update), flash[:notice]
assert Message.find_by_subject('Test reply')
end
def test_reply_with_empty_content_and_none_attachments
@request.session[:user_id] = 2
assert_no_difference 'Message.count' do
post :reply, :params => {
:board_id => 1,
:id => 1,
:reply => {
:content => 'This is a test reply',
:content => '',
:subject => 'Test reply'
}
}
reply = Message.order('id DESC').first
assert_redirected_to "/boards/1/topics/1?r=#{reply.id}"
assert_equal I18n.t(:notice_successful_update), flash[:notice]
assert Message.find_by_subject('Test reply')
end
assert_redirected_to '/boards/1/topics/1'
assert_nil flash[:notice]
end
def test_reply_with_empty_content_and_any_attachments_should_show_error_message
set_tmp_attachments_directory
@request.session[:user_id] = 2
assert_no_difference 'Message.count' do
post :reply, :params => {
:board_id => 1,
:id => 1,
:reply => {
:content => '',
:subject => 'Test reply'
},
:attachments => {
'1' => {
'file' => uploaded_test_file('testfile.txt', 'text/plain')
}
}
}
end
assert_select_error 'Content cannot be blank'
assert_select 'div#reply' do
assert_select 'input#message_subject[value=?]', 'Test reply'
assert_select 'textarea#message_content', :text => ''
assert_select 'span.attachments_fields' do
assert_select 'span#attachments_p0 input.filename[value=?]', 'testfile.txt'
end
end
end
def test_destroy_topic
(3-3/3)