Project

General

Profile

Defect #32664 » 32664_show_errormsg_submitting_reply.patch

Yuichi HARADA, 2019-12-25 02:32

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
......
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)
redirect_to board_message_path(@board, @topic, :r => @reply)
else
show
end
flash[:notice] = l(:notice_successful_update)
redirect_to board_message_path(@board, @topic, :r => @reply)
end
# Edit a message
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
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_invalid_value_should_show_error_message
@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_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 => ''
end
end
def test_destroy_topic
(2-2/3)