@@ -39,16 +39,17 class BoardsController < ApplicationController | |||||
39 | sort_init 'updated_on', 'desc' |
|
39 | sort_init 'updated_on', 'desc' | |
40 | sort_update 'created_on' => "#{Message.table_name}.created_on", |
|
40 | sort_update 'created_on' => "#{Message.table_name}.created_on", | |
41 | 'replies' => "#{Message.table_name}.replies_count", |
|
41 | 'replies' => "#{Message.table_name}.replies_count", | |
42 |
'updated_on' => "#{Message.table_name}. |
|
42 | 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)" | |
43 |
|
43 | |||
44 | @topic_count = @board.topics.count |
|
44 | @topic_count = @board.topics.count | |
45 | @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] |
|
45 | @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] | |
46 | @topics = @board.topics. |
|
46 | @topics = @board.topics. | |
47 | reorder("#{Message.table_name}.sticky DESC"). |
|
47 | reorder("#{Message.table_name}.sticky DESC"). | |
48 |
includes( |
|
48 | includes(:last_reply). | |
49 | limit(@topic_pages.items_per_page). |
|
49 | limit(@topic_pages.items_per_page). | |
50 | offset(@topic_pages.offset). |
|
50 | offset(@topic_pages.offset). | |
51 | order(sort_clause). |
|
51 | order(sort_clause). | |
|
52 | preload(:author, {:last_reply => :author}). | |||
52 | all |
|
53 | all | |
53 | @message = Message.new(:board => @board) |
|
54 | @message = Message.new(:board => @board) | |
54 | render :action => 'show', :layout => !request.xhr? |
|
55 | render :action => 'show', :layout => !request.xhr? |
@@ -69,6 +69,21 class BoardsControllerTest < ActionController::TestCase | |||||
69 | assert topics.first.updated_on < topics.second.updated_on |
|
69 | assert topics.first.updated_on < topics.second.updated_on | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
|
72 | def test_show_should_display_message_with_last_reply_first | |||
|
73 | Message.update_all(:sticky => 0) | |||
|
74 | ||||
|
75 | # Reply to an old topic | |||
|
76 | old_topic = Message.where(:board_id => 1, :parent_id => nil).order('created_on ASC').first | |||
|
77 | reply = Message.new(:board_id => 1, :subject => 'New reply', :content => 'New reply', :author_id => 2) | |||
|
78 | old_topic.children << reply | |||
|
79 | ||||
|
80 | get :show, :project_id => 1, :id => 1 | |||
|
81 | assert_response :success | |||
|
82 | topics = assigns(:topics) | |||
|
83 | assert_not_nil topics | |||
|
84 | assert_equal old_topic, topics.first | |||
|
85 | end | |||
|
86 | ||||
72 | def test_show_with_permission_should_display_the_new_message_form |
|
87 | def test_show_with_permission_should_display_the_new_message_form | |
73 | @request.session[:user_id] = 2 |
|
88 | @request.session[:user_id] = 2 | |
74 | get :show, :project_id => 1, :id => 1 |
|
89 | get :show, :project_id => 1, :id => 1 |
General Comments 0
You need to be logged in to leave comments.
Login now