Skip to content

Commit

Permalink
fix: gracefully handle an interactions value that is not an array
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 6, 2021
1 parent 627bfc3 commit a9a5df3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/pact_broker/pacts/sort_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ def self.verifiable_content_key_for pact_hash
end
end

def self.order_verifiable_content array
array_with_ordered_hashes = order_hash_keys(array)
array_with_ordered_hashes.sort{ |a, b| a.to_json <=> b.to_json }
def self.order_verifiable_content probably_array
# You never can tell what people will do...
if probably_array.is_a?(Array)
array_with_ordered_hashes = order_hash_keys(probably_array)
array_with_ordered_hashes.sort{ |a, b| a.to_json <=> b.to_json }
else
probably_array
end
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/pact_broker/pacts/sort_content_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ module Pacts
expect(SortContent.call(other_content)).to eq other_content
end
end

context "when interactions is a string" do
let(:other_content) do
{
'a' => 1,
'interactions' => 'interactions'
}
end

it "does not blow up" do
expect(SortContent.call(other_content)).to eq other_content
end
end
end
end
end

0 comments on commit a9a5df3

Please sign in to comment.