Skip to content

Commit 18b98c0

Browse files
author
Matt Baumgartner
committed
Fixed request decorator
1 parent e8ecfd4 commit 18b98c0

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ log
2929
reports
3030
Gemfile.lock
3131
build
32+
33+
vendor/bundle/

lib/pact/consumer_contract/request_decorator.rb

+4-28
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,18 @@ def to_json(options = {})
1515
def as_json options = {}
1616
hash = {
1717
method: request.method,
18-
path: path
18+
path: request.path
1919
}
20-
hash[:query] = query if request.specified?(:query)
21-
hash[:headers] = headers if request.specified?(:headers)
22-
hash[:body] = body if request.specified?(:body)
20+
hash[:query] = request.query if request.specified?(:query)
21+
hash[:headers] = request.headers if request.specified?(:headers)
22+
hash[:body] = request.body if request.specified?(:body)
2323
include_matching_rules? ? with_matching_rules(hash) : hash
2424
end
2525

2626
private
2727

2828
attr_reader :request
2929

30-
def path
31-
Pact::Reification.from_term(request.path)
32-
end
33-
34-
def headers
35-
Pact::Reification.from_term(request.headers)
36-
end
37-
38-
# This feels wrong to be checking the class type of the Query
39-
# Do this better somehow.
40-
def query
41-
Pact::Reification.from_term(request.query)
42-
end
43-
44-
# This feels wrong to be checking the class type of the body
45-
# Do this better somehow.
46-
def body
47-
if content_type_is_form && request.body.is_a?(Hash)
48-
URI.encode_www_form convert_hash_body_to_array_of_arrays
49-
else
50-
Pact::Reification.from_term(request.body)
51-
end
52-
end
53-
5430
def content_type_is_form
5531
request.content_type? 'application/x-www-form-urlencoded'
5632
end

0 commit comments

Comments
 (0)