Skip to content

Commit

Permalink
feat(matrix): allow a limit to be specified
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Nov 6, 2017
1 parent e896b7b commit 2a11334
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/pact_broker/matrix/parse_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def self.call query
if params.key?('groupby')
options[:groupby] = params['groupby']
end
if params.key?('limit')
options[:limit] = params['limit']
end
return selectors, options
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/pact_broker/matrix/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def find_all selectors, options
query = where_consumer_and_provider_in(selectors, query)
end

query = query.limit(options[:limit]) if options[:limit]

query.order(:verification_executed_at, :verification_id).all
end

Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/ui/controllers/matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Matrix < Base

get "/provider/:provider_name/consumer/:consumer_name" do
selectors = [{ pacticipant_name: params[:consumer_name] }, { pacticipant_name: params[:provider_name] } ]
lines = matrix_service.find(selectors)
lines = matrix_service.find(selectors, {latestby: 'cvpv', limit: 500})
lines = lines.collect{|line| PactBroker::UI::ViewDomain::MatrixLine.new(line) }.sort
locals = {
lines: lines,
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/pact_broker/matrix/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def shorten_rows rows
end

subject { shorten_rows(Repository.new.find(selectors, options)) }

let(:options) { { latestby: latestby } }
let(:latestby) { nil }
let(:a1_b1_n1) { "A1 B1 n1" }
Expand All @@ -50,6 +51,15 @@ def shorten_rows rows
let(:a1_c1_n1) { "A1 C1 n1" }
let(:a2_b__n_) { "A2 B? n?" }

context "when a limit is specified" do
let(:selectors) { build_selectors('A' => nil) }
let(:options) { {limit: 1} }

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
expect(subject.size).to eq 1
end
end

context "when just the consumer name is specified" do
let(:selectors) { build_selectors('A' => nil) }

Expand Down

0 comments on commit 2a11334

Please sign in to comment.