diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index bbc6a35d4..9bef7a2aa 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -50,8 +50,12 @@ class MessagesController < ApplicationController
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
@@ -82,9 +86,11 @@ class MessagesController < ApplicationController
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
diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb
index b8abf0321..cbb5cb112 100644
--- a/app/views/messages/show.html.erb
+++ b/app/views/messages/show.html.erb
@@ -23,6 +23,7 @@
<%= authoring @topic.created_on, @topic.author %>
@@ -81,7 +82,7 @@
<% if !@topic.locked? && authorize_for('messages', 'reply') %>
<%= toggle_link l(:button_reply), "reply", :focus => 'message_content' %>
-
+
<%= 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) %>
diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb
index ad193b119..9f14a0e19 100644
--- a/test/functional/messages_controller_test.rb
+++ b/test/functional/messages_controller_test.rb
@@ -217,18 +217,39 @@ class MessagesControllerTest < Redmine::ControllerTest
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