Skip to content

Commit 9bb87ec

Browse files
committed
feat(index): enable pagination feature
1 parent d89d90c commit 9bb87ec

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/pact_broker/ui/controllers/index.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ class Index < Base
1515
tags = params[:tags] == 'true' ? true : [*params[:tags]].compact
1616
end
1717
page_number = params[:page]&.to_i || 1
18-
page_size = params[:pageSize]&.to_i || 30
18+
# Make page size smaller for data intensive query
19+
page_size = params[:pageSize]&.to_i || ( params[:tags] == true ? 30 : 100)
1920
options = {
2021
tags: tags,
2122
page_number: page_number,
2223
page_size: page_size
2324
}
2425

25-
options[:optimised] = true if params[:optimised] == 'true'
26+
# TODO remove this code when verified
27+
options[:optimised] = true unless params[:optimised] == 'false'
2628
index_items = ViewDomain::IndexItems.new(index_service.find_index_items(options))
2729

2830
page = tags ? :'index/show-with-tags' : :'index/show'

spec/lib/pact_broker/ui/controllers/index_spec.rb

+12-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,18 @@ module Controllers
3838
end
3939

4040
context "when pagination parameters are not present" do
41-
it "passes through default pagination parameters to the search" do
42-
expect(PactBroker::Index::Service).to receive(:find_index_items).with(hash_including(page_number: 1, page_size: 30))
43-
get "/"
41+
context "when tags=true" do
42+
it "passes through default pagination parameters to the search with page_size=30" do
43+
expect(PactBroker::Index::Service).to receive(:find_index_items).with(hash_including(page_number: 1, page_size: 30))
44+
get "/", { tags: 'true' }
45+
end
46+
end
47+
48+
context "when not tags=true" do
49+
it "passes through default pagination parameters to the search with page_size=100" do
50+
expect(PactBroker::Index::Service).to receive(:find_index_items).with(hash_including(page_number: 1, page_size: 100))
51+
get "/"
52+
end
4453
end
4554
end
4655

0 commit comments

Comments
 (0)