mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00
Merge pull request #4981 from dmacjam/fix_limited_search_results
FIX: limited search results
This commit is contained in:
@ -843,4 +843,39 @@ describe Search do
|
||||
end
|
||||
end
|
||||
|
||||
context 'pagination' do
|
||||
let(:number_of_results) { 2 }
|
||||
let!(:post1) { Fabricate(:post, raw: 'hello hello hello hello hello')}
|
||||
let!(:post2) { Fabricate(:post, raw: 'hello hello hello hello')}
|
||||
let!(:post3) { Fabricate(:post, raw: 'hello hello hello')}
|
||||
let!(:post4) { Fabricate(:post, raw: 'hello hello')}
|
||||
let!(:post5) { Fabricate(:post, raw: 'hello')}
|
||||
before do
|
||||
Search.stubs(:per_filter).returns(number_of_results)
|
||||
end
|
||||
|
||||
it 'returns more results flag' do
|
||||
results = Search.execute('hello', type_filter: 'topic')
|
||||
results2 = Search.execute('hello', type_filter: 'topic', page: 2)
|
||||
|
||||
expect(results.posts.length).to eq(number_of_results)
|
||||
expect(results.posts.map(&:id)).to eq([post1.id, post2.id])
|
||||
expect(results.more_full_page_results).to eq(true)
|
||||
expect(results2.posts.length).to eq(number_of_results)
|
||||
expect(results2.posts.map(&:id)).to eq([post3.id, post4.id])
|
||||
expect(results2.more_full_page_results).to eq(true)
|
||||
end
|
||||
|
||||
it 'correctly search with page parameter' do
|
||||
search = Search.new('hello', type_filter: 'topic', page: 3)
|
||||
results = search.execute
|
||||
|
||||
expect(search.offset).to eq(2 * number_of_results)
|
||||
expect(results.posts.length).to eq(1)
|
||||
expect(results.posts).to eq([post5])
|
||||
expect(results.more_full_page_results).to eq(nil)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user