Patch #26030 » reply_order.patch
app/controllers/messages_controller.rb (working copy) | ||
---|---|---|
34 | 34 |
def show |
35 | 35 |
page = params[:page] |
36 | 36 |
# Find the page of the requested reply |
37 |
replies_order = User.current.wants_comments_in_reverse_order? ? 'DESC' : 'ASC' |
|
38 |
@replies = @topic.children. |
|
39 |
includes(:author, :attachments, {:board => :project}). |
|
40 |
reorder("#{Message.table_name}.created_on #{replies_order}, #{Message.table_name}.id #{replies_order}") |
|
41 | ||
37 | 42 |
if params[:r] && page.nil? |
38 |
offset = @topic.children.where("#{Message.table_name}.id < ?", params[:r].to_i).count
|
|
43 |
offset = @replies.pluck(:id).index(params[:r].to_i)
|
|
39 | 44 |
page = 1 + offset / REPLIES_PER_PAGE |
40 | 45 |
end |
41 | 46 | |
42 |
@reply_count = @topic.children.count
|
|
47 |
@reply_count = @replies.count
|
|
43 | 48 |
@reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page |
44 |
@replies = @topic.children. |
|
45 |
includes(:author, :attachments, {:board => :project}). |
|
46 |
reorder("#{Message.table_name}.created_on ASC, #{Message.table_name}.id ASC"). |
|
49 |
@replies = @replies. |
|
47 | 50 |
limit(@reply_pages.per_page). |
48 | 51 |
offset(@reply_pages.offset). |
49 | 52 |
to_a |
test/integration/messages_test.rb (working copy) | ||
---|---|---|
1 |
require File.expand_path('../../test_helper', __FILE__) |
|
2 |
|
|
3 |
class MessagesTest < Redmine::IntegrationTest |
|
4 |
fixtures :projects, :users, :email_addresses, :user_preferences, :members, |
|
5 |
:member_roles, :roles, :boards, :messages, :enabled_modules |
|
6 |
|
|
7 |
def setup |
|
8 |
message = Message.find(1) |
|
9 |
assert_difference 'Message.count', 60 do |
|
10 |
60.times do |
|
11 |
message.children << Message.new( |
|
12 |
:subject => 'Reply', |
|
13 |
:content => 'Reply body', |
|
14 |
:author_id => 2, |
|
15 |
:board_id => 1) |
|
16 |
end |
|
17 |
end |
|
18 |
@reply_ids = message.children.map(&:id).sort |
|
19 |
|
|
20 |
log_user('jsmith', 'jsmith') |
|
21 |
end |
|
22 |
|
|
23 |
def test_show_with_pagination_should_ascending_order |
|
24 |
post '/my/account', :pref => { :comments_sorting => 'asc' } |
|
25 |
get '/boards/1/topics/1', :r => @reply_ids.last |
|
26 |
|
|
27 |
assert !User.current.wants_comments_in_reverse_order? |
|
28 |
assert_select 'span.pagination > ul.pages > li.current > span', text: '3' |
|
29 |
end |
|
30 |
|
|
31 |
def test_show_with_pagination_should_descending_order |
|
32 |
post '/my/account', :pref => { :comments_sorting => 'desc' } |
|
33 |
get '/boards/1/topics/1', :r => @reply_ids.last |
|
34 |
|
|
35 |
assert User.current.wants_comments_in_reverse_order? |
|
36 |
assert_select 'span.pagination > ul.pages > li.current > span', text: '1' |
|
37 |
end |
|
38 |
|
|
39 |
end |