Skip to content

Commit

Permalink
feat(index): enable pagination feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Nov 17, 2019
1 parent d89d90c commit 9bb87ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/pact_broker/ui/controllers/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 12 additions & 3 deletions spec/lib/pact_broker/ui/controllers/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9bb87ec

Please sign in to comment.