Skip to content

Commit 2a11334

Browse files
committed
feat(matrix): allow a limit to be specified
1 parent e896b7b commit 2a11334

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

lib/pact_broker/matrix/parse_query.rb

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def self.call query
2828
if params.key?('groupby')
2929
options[:groupby] = params['groupby']
3030
end
31+
if params.key?('limit')
32+
options[:limit] = params['limit']
33+
end
3134
return selectors, options
3235
end
3336
end

lib/pact_broker/matrix/repository.rb

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def find_all selectors, options
7070
query = where_consumer_and_provider_in(selectors, query)
7171
end
7272

73+
query = query.limit(options[:limit]) if options[:limit]
74+
7375
query.order(:verification_executed_at, :verification_id).all
7476
end
7577

lib/pact_broker/ui/controllers/matrix.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Matrix < Base
1111

1212
get "/provider/:provider_name/consumer/:consumer_name" do
1313
selectors = [{ pacticipant_name: params[:consumer_name] }, { pacticipant_name: params[:provider_name] } ]
14-
lines = matrix_service.find(selectors)
14+
lines = matrix_service.find(selectors, {latestby: 'cvpv', limit: 500})
1515
lines = lines.collect{|line| PactBroker::UI::ViewDomain::MatrixLine.new(line) }.sort
1616
locals = {
1717
lines: lines,

spec/lib/pact_broker/matrix/repository_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def shorten_rows rows
4242
end
4343

4444
subject { shorten_rows(Repository.new.find(selectors, options)) }
45+
4546
let(:options) { { latestby: latestby } }
4647
let(:latestby) { nil }
4748
let(:a1_b1_n1) { "A1 B1 n1" }
@@ -50,6 +51,15 @@ def shorten_rows rows
5051
let(:a1_c1_n1) { "A1 C1 n1" }
5152
let(:a2_b__n_) { "A2 B? n?" }
5253

54+
context "when a limit is specified" do
55+
let(:selectors) { build_selectors('A' => nil) }
56+
let(:options) { {limit: 1} }
57+
58+
it "returns fewer rows than the limit (because some of the logic is done in the code, there may be fewer than the limit - need to fix this)" do
59+
expect(subject.size).to eq 1
60+
end
61+
end
62+
5363
context "when just the consumer name is specified" do
5464
let(:selectors) { build_selectors('A' => nil) }
5565

0 commit comments

Comments
 (0)