mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
FIX: accessing a topic with a 'page' parameter
This commit is contained in:
parent
5beaf61ac0
commit
7105349f1f
2 changed files with 18 additions and 7 deletions
|
@ -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
|
||||
|
@ -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 a new issue