Defect #32664 » 32664_show_errormsg_submitting_reply.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 |
... | ... | |
82 | 86 |
call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) |
83 | 87 |
attachments = Attachment.attach_files(@reply, params[:attachments]) |
84 | 88 |
render_attachment_warning_if_needed(@reply) |
89 |
flash[:notice] = l(:notice_successful_update) |
|
90 |
redirect_to board_message_path(@board, @topic, :r => @reply) |
|
91 |
else |
|
92 |
show |
|
85 | 93 |
end |
86 |
flash[:notice] = l(:notice_successful_update) |
|
87 |
redirect_to board_message_path(@board, @topic, :r => @reply) |
|
88 | 94 |
end |
89 | 95 | |
90 | 96 |
# Edit a message |
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 | ||
---|---|---|
217 | 217 | |
218 | 218 |
def test_reply |
219 | 219 |
@request.session[:user_id] = 2 |
220 |
post :reply, :params => { |
|
220 |
assert_difference 'Message.count' do |
|
221 |
post :reply, :params => { |
|
222 |
:board_id => 1, |
|
223 |
:id => 1, |
|
224 |
:reply => { |
|
225 |
:content => 'This is a test reply', |
|
226 |
:subject => 'Test reply' |
|
227 |
} |
|
228 |
} |
|
229 |
end |
|
230 |
reply = Message.order('id DESC').first |
|
231 |
assert_redirected_to "/boards/1/topics/1?r=#{reply.id}" |
|
232 |
assert_equal I18n.t(:notice_successful_update), flash[:notice] |
|
233 |
assert Message.find_by_subject('Test reply') |
|
234 |
end |
|
235 | ||
236 |
def test_reply_with_invalid_value_should_show_error_message |
|
237 |
@request.session[:user_id] = 2 |
|
238 |
assert_no_difference 'Message.count' do |
|
239 |
post :reply, :params => { |
|
221 | 240 |
:board_id => 1, |
222 | 241 |
:id => 1, |
223 | 242 |
:reply => { |
224 |
:content => 'This is a test reply',
|
|
243 |
:content => '', |
|
225 | 244 |
:subject => 'Test reply' |
226 | 245 |
} |
227 | 246 |
} |
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') |
|
247 |
end |
|
248 |
assert_select_error 'Content cannot be blank' |
|
249 |
assert_select 'div#reply' do |
|
250 |
assert_select 'input#message_subject[value=?]', 'Test reply' |
|
251 |
assert_select 'textarea#message_content', :text => '' |
|
252 |
end |
|
232 | 253 |
end |
233 | 254 | |
234 | 255 |
def test_destroy_topic |