From 9bb87eca8bc5a8d14336b68a2d3ddab833c438ca Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 18 Nov 2019 10:36:05 +1100 Subject: [PATCH] feat(index): enable pagination feature --- lib/pact_broker/ui/controllers/index.rb | 6 ++++-- spec/lib/pact_broker/ui/controllers/index_spec.rb | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/pact_broker/ui/controllers/index.rb b/lib/pact_broker/ui/controllers/index.rb index 4edd79b86..319946753 100644 --- a/lib/pact_broker/ui/controllers/index.rb +++ b/lib/pact_broker/ui/controllers/index.rb @@ -15,14 +15,16 @@ class Index < Base tags = params[:tags] == 'true' ? true : [*params[:tags]].compact end page_number = params[:page]&.to_i || 1 - page_size = params[:pageSize]&.to_i || 30 + # Make page size smaller for data intensive query + page_size = params[:pageSize]&.to_i || ( params[:tags] == true ? 30 : 100) options = { tags: tags, page_number: page_number, page_size: page_size } - options[:optimised] = true if params[:optimised] == 'true' + # TODO remove this code when verified + options[:optimised] = true unless params[:optimised] == 'false' index_items = ViewDomain::IndexItems.new(index_service.find_index_items(options)) page = tags ? :'index/show-with-tags' : :'index/show' diff --git a/spec/lib/pact_broker/ui/controllers/index_spec.rb b/spec/lib/pact_broker/ui/controllers/index_spec.rb index d67fd1236..52f3232b6 100644 --- a/spec/lib/pact_broker/ui/controllers/index_spec.rb +++ b/spec/lib/pact_broker/ui/controllers/index_spec.rb @@ -38,9 +38,18 @@ module Controllers end context "when pagination parameters are not present" do - it "passes through default pagination parameters to the search" do - expect(PactBroker::Index::Service).to receive(:find_index_items).with(hash_including(page_number: 1, page_size: 30)) - get "/" + context "when tags=true" do + it "passes through default pagination parameters to the search with page_size=30" do + expect(PactBroker::Index::Service).to receive(:find_index_items).with(hash_including(page_number: 1, page_size: 30)) + get "/", { tags: 'true' } + end + end + + context "when not tags=true" do + it "passes through default pagination parameters to the search with page_size=100" do + expect(PactBroker::Index::Service).to receive(:find_index_items).with(hash_including(page_number: 1, page_size: 100)) + get "/" + end end end