FIX: Don't bother with negative offsets
This commit is contained in:
parent
66fb02acad
commit
49a6d0b789
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue