From abcab9eabc73235684846c2bdbf4561bd96f0688 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 1 Nov 2017 10:15:25 +1100 Subject: [PATCH] feat(matrix): parse latest=true and tag=TAG in matrix query --- lib/pact_broker/matrix/parse_query.rb | 9 ++++++- .../pact_broker/matrix/parse_query_spec.rb | 26 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/pact_broker/matrix/parse_query.rb b/lib/pact_broker/matrix/parse_query.rb index 3185c968b..3f9cb29eb 100644 --- a/lib/pact_broker/matrix/parse_query.rb +++ b/lib/pact_broker/matrix/parse_query.rb @@ -5,7 +5,14 @@ module Matrix class ParseQuery def self.call query params = Rack::Utils.parse_nested_query(query) - selectors = (params['q'] || []).collect{ |i| { pacticipant_name: i['pacticipant'], pacticipant_version_number: i['version'] } } + selectors = (params['q'] || []).collect do |i| + p = {} + p[:pacticipant_name] = i['pacticipant'] if i['pacticipant'] + p[:pacticipant_version_number] = i['version'] if i['version'] + p[:latest] = true if i['latest'] == 'true' + p[:tag] = i['tag'] if i['tag'] + p + end options = {} if params.key?('success') && params['success'].is_a?(Array) options[:success] = params['success'].collect do | value | diff --git a/spec/lib/pact_broker/matrix/parse_query_spec.rb b/spec/lib/pact_broker/matrix/parse_query_spec.rb index ff131bbb2..0d8c4d8a6 100644 --- a/spec/lib/pact_broker/matrix/parse_query_spec.rb +++ b/spec/lib/pact_broker/matrix/parse_query_spec.rb @@ -32,7 +32,7 @@ module Matrix let(:query) { "q[][wrong]=Foo&q[][blah]=1.2.3" } it "returns nil keys or values" do - expect(subject.first).to eq [{ pacticipant_name: nil, pacticipant_version_number: nil }] + expect(subject.first).to eq [{}] end end @@ -73,6 +73,30 @@ module Matrix expect(subject.last).to eq(success: [nil]) end end + + context "when latest is true" do + let(:query) { "q[][pacticipant]=Foo&q[][latest]=true" } + + it "returns a selector with latest true" do + expect(subject.first).to eq [{ pacticipant_name: 'Foo', latest: true }] + end + end + + context "when latest is not true" do + let(:query) { "q[][pacticipant]=Foo&q[][latest]=false" } + + it "returns a selector with no latest key" do + expect(subject.first).to eq [{ pacticipant_name: 'Foo' }] + end + end + + context "when there is a tag" do + let(:query) { "q[][pacticipant]=Foo&q[][tag]=prod" } + + it "returns a selector with a tag" do + expect(subject.first).to eq [{ pacticipant_name: 'Foo', tag: 'prod' }] + end + end end end end