File tree 2 files changed +33
-2
lines changed
spec/lib/pact_broker/matrix
2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,14 @@ module Matrix
5
5
class ParseQuery
6
6
def self . call query
7
7
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
9
16
options = { }
10
17
if params . key? ( 'success' ) && params [ 'success' ] . is_a? ( Array )
11
18
options [ :success ] = params [ 'success' ] . collect do | value |
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ module Matrix
32
32
let ( :query ) { "q[][wrong]=Foo&q[][blah]=1.2.3" }
33
33
34
34
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 [ { } ]
36
36
end
37
37
end
38
38
@@ -73,6 +73,30 @@ module Matrix
73
73
expect ( subject . last ) . to eq ( success : [ nil ] )
74
74
end
75
75
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
76
100
end
77
101
end
78
102
end
You can’t perform that action at this time.
0 commit comments