Skip to content

Commit

Permalink
feat(matrix): parse latest=true and tag=TAG in matrix query
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 31, 2017
1 parent db2e676 commit abcab9e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/pact_broker/matrix/parse_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
26 changes: 25 additions & 1 deletion spec/lib/pact_broker/matrix/parse_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit abcab9e

Please sign in to comment.