mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
FIX: accessing a topic with a 'page' parameter
This commit is contained in:
parent
5beaf61ac0
commit
7105349f1f
@ -140,8 +140,8 @@ class TopicView
|
||||
end
|
||||
|
||||
def filter_posts_paged(page)
|
||||
page ||= 0
|
||||
min = (SiteSetting.posts_per_page * page)
|
||||
page = [page, 1].max
|
||||
min = SiteSetting.posts_per_page * (page - 1)
|
||||
max = min + SiteSetting.posts_per_page
|
||||
filter_posts_in_range(min, max)
|
||||
end
|
||||
@ -172,7 +172,7 @@ class TopicView
|
||||
@posts = @filtered_posts.order('sort_order').where("sort_order > ?", sort_order)
|
||||
@posts = @posts.includes(:reply_to_user).includes(:topic).joins(:user).limit(@limit)
|
||||
end
|
||||
|
||||
|
||||
def filter_best(max)
|
||||
@index_offset = 0
|
||||
@posts = @filtered_posts.order('percent_rank asc, sort_order asc').where("post_number > 1")
|
||||
@ -283,7 +283,6 @@ class TopicView
|
||||
private
|
||||
|
||||
def filter_posts_in_range(min, max)
|
||||
|
||||
max_index = (filtered_post_ids.length - 1)
|
||||
|
||||
# If we're off the charts, return nil
|
||||
|
@ -334,12 +334,24 @@ describe TopicsController do
|
||||
|
||||
context 'filters' do
|
||||
|
||||
|
||||
it 'grabs first page when no post number is selected' do
|
||||
TopicView.any_instance.expects(:filter_posts_paged).with(0)
|
||||
it 'grabs first page when no filter is provided' do
|
||||
SiteSetting.stubs(:posts_per_page).returns(20)
|
||||
TopicView.any_instance.expects(:filter_posts_in_range).with(0, 20)
|
||||
xhr :get, :show, id: topic.id
|
||||
end
|
||||
|
||||
it 'grabs first page when first page is provided' do
|
||||
SiteSetting.stubs(:posts_per_page).returns(20)
|
||||
TopicView.any_instance.expects(:filter_posts_in_range).with(0, 20)
|
||||
xhr :get, :show, id: topic.id, page: 1
|
||||
end
|
||||
|
||||
it 'grabs correct range when a page number is provided' do
|
||||
SiteSetting.stubs(:posts_per_page).returns(20)
|
||||
TopicView.any_instance.expects(:filter_posts_in_range).with(20, 40)
|
||||
xhr :get, :show, id: topic.id, page: 2
|
||||
end
|
||||
|
||||
it 'delegates a post_number param to TopicView#filter_posts_near' do
|
||||
TopicView.any_instance.expects(:filter_posts_near).with(p2.post_number)
|
||||
xhr :get, :show, id: topic.id, post_number: p2.post_number
|
||||
|
Loading…
Reference in New Issue
Block a user