diff --git a/doc/pacts/markdown/Pact Broker Client - Pact Broker.md b/doc/pacts/markdown/Pact Broker Client - Pact Broker.md index 778d56e3..a96d2396 100644 --- a/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +++ b/doc/pacts/markdown/Pact Broker Client - Pact Broker.md @@ -434,7 +434,7 @@ Given **the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6 an { "method": "get", "path": "/matrix", - "query": "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp" + "query": "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp&latest=true" } ``` Pact Broker will respond with: diff --git a/lib/pact_broker/client/matrix.rb b/lib/pact_broker/client/matrix.rb index 71e8bd69..e5b3a53f 100644 --- a/lib/pact_broker/client/matrix.rb +++ b/lib/pact_broker/client/matrix.rb @@ -9,7 +9,7 @@ def get selectors, options = {} query = { q: convert_selector_hashes_to_params(selectors), latestby: latestby - }.merge(query_options(options)) + }.merge(query_options(options, selectors)) response = self.class.get("/matrix", query: query, headers: default_get_headers) response = handle_response(response) do Matrix::Resource.new(JSON.parse(response.body, symbolize_names: true)) @@ -41,7 +41,7 @@ def handle_response response end end - def query_options(options) + def query_options(options, selectors) opts = {} if options.key?(:success) opts[:success] = [*options[:success]] @@ -50,6 +50,8 @@ def query_options(options) if options[:to_tag] opts[:latest] = 'true' opts[:tag] = options[:to_tag] + elsif selectors.size == 1 + opts[:latest] = 'true' end opts end diff --git a/spec/pacts/pact_broker_client-pact_broker.json b/spec/pacts/pact_broker_client-pact_broker.json index 7861ef32..f1bbcae5 100644 --- a/spec/pacts/pact_broker_client-pact_broker.json +++ b/spec/pacts/pact_broker_client-pact_broker.json @@ -292,7 +292,7 @@ "request": { "method": "get", "path": "/matrix", - "query": "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp" + "query": "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp&latest=true" }, "response": { "status": 200, diff --git a/spec/service_providers/pact_broker_client_matrix_spec.rb b/spec/service_providers/pact_broker_client_matrix_spec.rb index 711709eb..e15f9e95 100644 --- a/spec/service_providers/pact_broker_client_matrix_spec.rb +++ b/spec/service_providers/pact_broker_client_matrix_spec.rb @@ -67,7 +67,7 @@ module PactBroker::Client with( method: :get, path: "/matrix", - query: "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp" + query: "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp&latest=true" ). will_respond_with( status: 200,