From 4eb7f7cd1061437257033a0e9df19371817a6995 Mon Sep 17 00:00:00 2001 From: Jakub Macina Date: Fri, 21 Jul 2017 10:43:02 +0200 Subject: [PATCH] Add rspec tests for search pagination. --- spec/components/search_spec.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index a17c6e8f609..395255274e8 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -802,4 +802,32 @@ describe Search do end end + context 'pagination' do + let(:number_of_results) { 2 } + before do + 5.times { Fabricate(:post) } + 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.more_full_page_results).to eq(true) + expect(results2.posts.length).to eq(number_of_results) + 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.more_full_page_results).to eq(nil) + end + + end + end