Skip to content

Commit

Permalink
fix: serialize ArrayLike in query params without wrapping another arr…
Browse files Browse the repository at this point in the history
…ay around it
  • Loading branch information
bethesque committed Jun 27, 2018
1 parent 5e98d17 commit b4a9ec7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pact/consumer_contract/query_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def convert_to_hash_of_arrays(query)
def insert(hash, k, v)
if Hash === v
v.each {|k2, v2| insert(hash, :"#{k}[#{k2}]", v2) }
elsif Pact::ArrayLike === v
hash[k.to_sym] = v
else
hash[k.to_sym] = [*v]
end
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/pact/consumer_contract/query_hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ module Pact
end

describe "#to_json" do
context "when the query contains an ArrayLike" do
let(:query) { { foo: Pact.each_like("1"), bar: "2" } }
let(:expected_json) do
{
foo: Pact.each_like("1"),
bar: ["2"]
}.to_json
end

it "serialises the ArrayLike without wrapping an array around it" do
expect(subject.to_json).to eq expected_json
end
end

context "when the query contains a Pact::Term" do
let(:term) { Pact::Term.new(generate: "thing", matcher: /th/) }
let(:query) { { param: term } }
Expand Down

0 comments on commit b4a9ec7

Please sign in to comment.