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
This commit is contained in:
Jean-Philippe Lang 2012-06-16 19:34:19 +00:00
parent 897e83a556
commit 542b355210
2 changed files with 16 additions and 2 deletions

View 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?
}

View 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