]> source.dussan.org Git - redmine.git/commitdiff
Fixed that sticky messages are not displayed first (#11170).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 16 Jun 2012 19:34:19 +0000 (19:34 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 16 Jun 2012 19:34:19 +0000 (19:34 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9836 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 40552a0c949577118b463dafc004ede98ec0e6f9..3dea52bfbe38ddbb26a3cc34f64065cb2b19b39d 100644 (file)
@@ -43,10 +43,10 @@ class BoardsController < ApplicationController
 
         @topic_count = @board.topics.count
         @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
-        @topics =  @board.topics.find :all, :order => ["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '),
+        @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
+                                      :offset =>  @topic_pages.current.offset)
         @message = Message.new(:board => @board)
         render :action => 'show', :layout => !request.xhr?
       }
index 744177bd3d1210e6b3916d93ad715e7acd6ebac5..1c4ac67d447d138c68829fa2f493368ea5fa9b65 100644 (file)
@@ -55,6 +55,20 @@ class BoardsControllerTest < ActionController::TestCase
     assert_not_nil assigns(:topics)
   end
 
+  def test_show_should_display_sticky_messages_first
+    Message.update_all(:sticky => 0)
+    Message.update_all({:sticky => 1}, {:id => 1})
+
+    get :show, :project_id => 1, :id => 1
+    assert_response :success
+
+    topics = assigns(:topics)
+    assert_not_nil topics
+    assert topics.size > 1, "topics size was #{topics.size}"
+    assert topics.first.sticky?
+    assert topics.first.updated_on < topics.second.updated_on
+  end
+
   def test_show_with_permission_should_display_the_new_message_form
     @request.session[:user_id] = 2
     get :show, :project_id => 1, :id => 1