From 542b355210f901e9628127b8ae9a4de1787710f7 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 16 Jun 2012 19:34:19 +0000 Subject: [PATCH] Fixed that sticky messages are not displayed first (#11170). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9836 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/boards_controller.rb | 4 ++-- test/functional/boards_controller_test.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 40552a0c9..3dea52bfb 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -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? } diff --git a/test/functional/boards_controller_test.rb b/test/functional/boards_controller_test.rb index 744177bd3..1c4ac67d4 100644 --- a/test/functional/boards_controller_test.rb +++ b/test/functional/boards_controller_test.rb @@ -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