FIX: Don't bother with negative offsets

This commit is contained in:
Robin Ward 2016-05-09 16:33:55 -04:00
parent 66fb02acad
commit 49a6d0b789
No known key found for this signature in database
GPG Key ID: 0E091E2B4ED1B83D
2 changed files with 15 additions and 2 deletions

View File

@ -374,7 +374,11 @@ class TopicQuery
result = result.limit(options[:per_page]) unless options[:limit] == false
result = result.visible if options[:visible] || @user.nil? || @user.regular?
result = result.offset(options[:page].to_i * options[:per_page]) if options[:page]
if options[:page]
offset = options[:page].to_i * options[:per_page]
result = result.offset(offset) if offset > 0
end
result
end
@ -463,7 +467,11 @@ class TopicQuery
result = result.visible if options[:visible]
result = result.where.not(topics: {id: options[:except_topic_ids]}).references(:topics) if options[:except_topic_ids]
result = result.offset(options[:page].to_i * options[:per_page]) if options[:page]
if options[:page]
offset = options[:page].to_i * options[:per_page]
result.offset(offset) if offset > 0
end
if options[:topic_ids]
result = result.where('topics.id in (?)', options[:topic_ids]).references(:topics)

View File

@ -41,6 +41,11 @@ describe ListController do
expect(parsed["topic_list"]["topics"].length).to eq(1)
end
it "doesn't throw an error with a negative page" do
xhr :get, :top, page: -1024
expect(response).to be_success
end
end
describe 'RSS feeds' do