]> source.dussan.org Git - redmine.git/commitdiff
Backported r11424 from trunk (#12243).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 11 Mar 2013 18:27:46 +0000 (18:27 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 11 Mar 2013 18:27:46 +0000 (18:27 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.2-stable@11594 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/boards_controller.rb
test/functional/boards_controller_test.rb

index cea2cd3bdc00c673c8fc11cfaee8de68a6f5f20b..ff9661ffbfc4d040ba6365062688827c6df141df 100644 (file)
@@ -39,14 +39,18 @@ class BoardsController < ApplicationController
         sort_init 'updated_on', 'desc'
         sort_update    'created_on' => "#{Message.table_name}.created_on",
                     'replies' => "#{Message.table_name}.replies_count",
-                    'updated_on' => "#{Message.table_name}.updated_on"
+                    'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
 
         @topic_count = @board.topics.count
         @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
-        @topics =  @board.topics.reorder("#{Message.table_name}.sticky DESC").order(sort_clause).all(
-                                      :include => [:author, {:last_reply => :author}],
-                                      :limit  =>  @topic_pages.items_per_page,
-                                      :offset =>  @topic_pages.current.offset)
+        @topics =  @board.topics.
+          reorder("#{Message.table_name}.sticky DESC").
+          includes(:last_reply).
+          limit(@topic_pages.items_per_page).
+          offset(@topic_pages.current.offset).
+          order(sort_clause).
+          preload(:author, {:last_reply => :author}).
+          all
         @message = Message.new(:board => @board)
         render :action => 'show', :layout => !request.xhr?
       }
index 8afe4f748ff7830c4dc73077c887b4d542919798..abde800c81e5ad7684a1800dcdb8bbcf0b0b11e2 100644 (file)
@@ -69,6 +69,21 @@ class BoardsControllerTest < ActionController::TestCase
     assert topics.first.updated_on < topics.second.updated_on
   end
 
+  def test_show_should_display_message_with_last_reply_first
+    Message.update_all(:sticky => 0)
+
+    # Reply to an old topic
+    old_topic = Message.where(:board_id => 1, :parent_id => nil).order('created_on ASC').first
+    reply = Message.new(:board_id => 1, :subject => 'New reply', :content => 'New reply', :author_id => 2)
+    old_topic.children << reply
+
+    get :show, :project_id => 1, :id => 1
+    assert_response :success
+    topics = assigns(:topics)
+    assert_not_nil topics
+    assert_equal old_topic, topics.first
+  end
+
   def test_show_with_permission_should_display_the_new_message_form
     @request.session[:user_id] = 2
     get :show, :project_id => 1, :id => 1