Skip to content

Commit abcab9e

Browse files
committed
feat(matrix): parse latest=true and tag=TAG in matrix query
1 parent db2e676 commit abcab9e

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/pact_broker/matrix/parse_query.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ module Matrix
55
class ParseQuery
66
def self.call query
77
params = Rack::Utils.parse_nested_query(query)
8-
selectors = (params['q'] || []).collect{ |i| { pacticipant_name: i['pacticipant'], pacticipant_version_number: i['version'] } }
8+
selectors = (params['q'] || []).collect do |i|
9+
p = {}
10+
p[:pacticipant_name] = i['pacticipant'] if i['pacticipant']
11+
p[:pacticipant_version_number] = i['version'] if i['version']
12+
p[:latest] = true if i['latest'] == 'true'
13+
p[:tag] = i['tag'] if i['tag']
14+
p
15+
end
916
options = {}
1017
if params.key?('success') && params['success'].is_a?(Array)
1118
options[:success] = params['success'].collect do | value |

spec/lib/pact_broker/matrix/parse_query_spec.rb

+25-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Matrix
3232
let(:query) { "q[][wrong]=Foo&q[][blah]=1.2.3" }
3333

3434
it "returns nil keys or values" do
35-
expect(subject.first).to eq [{ pacticipant_name: nil, pacticipant_version_number: nil }]
35+
expect(subject.first).to eq [{}]
3636
end
3737
end
3838

@@ -73,6 +73,30 @@ module Matrix
7373
expect(subject.last).to eq(success: [nil])
7474
end
7575
end
76+
77+
context "when latest is true" do
78+
let(:query) { "q[][pacticipant]=Foo&q[][latest]=true" }
79+
80+
it "returns a selector with latest true" do
81+
expect(subject.first).to eq [{ pacticipant_name: 'Foo', latest: true }]
82+
end
83+
end
84+
85+
context "when latest is not true" do
86+
let(:query) { "q[][pacticipant]=Foo&q[][latest]=false" }
87+
88+
it "returns a selector with no latest key" do
89+
expect(subject.first).to eq [{ pacticipant_name: 'Foo' }]
90+
end
91+
end
92+
93+
context "when there is a tag" do
94+
let(:query) { "q[][pacticipant]=Foo&q[][tag]=prod" }
95+
96+
it "returns a selector with a tag" do
97+
expect(subject.first).to eq [{ pacticipant_name: 'Foo', tag: 'prod' }]
98+
end
99+
end
76100
end
77101
end
78102
end

0 commit comments

Comments
 (0)