Skip to content

Commit

Permalink
feat: remove whitespace from pact content when saving to database
Browse files Browse the repository at this point in the history
Closes: #260
  • Loading branch information
bethesque committed Apr 25, 2019
1 parent 40be97d commit 1f53682
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/pact_broker/pacts/pact_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def self.from_path_info path_info
def self.from_request request, path_info
json_content = request.body.to_s
parsed_content = begin
JSON.parse(json_content, PACT_PARSING_OPTIONS)
parsed = JSON.parse(json_content, PACT_PARSING_OPTIONS)
json_content = parsed.to_json # remove whitespace
parsed
rescue
{}
end
Expand Down
6 changes: 5 additions & 1 deletion spec/lib/pact_broker/pacts/pact_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ module Pacts
end

it "extracts the json_content" do
expect(subject.json_content).to eq body
expect(subject.json_content).to eq JSON.parse(body).to_json
end

it "removes whitespace from the json_content" do
expect(subject.json_content).to_not include "\n"
end

it "extracts the consumer name from the pact" do
Expand Down

0 comments on commit 1f53682

Please sign in to comment.