@@ -58,12 +58,12 @@ def initialize(responses)
58
58
end
59
59
60
60
[ :post , :patch , :put , :get , :delete , :head ] . each do |method |
61
- # def post(path, request_headers = {}, body = nil, status = 200, response_headers = {})
62
- # @responses[Request.new(:post, path, nil, request_headers)] = Response.new(body || "", status, response_headers)
61
+ # def post(path, request_headers = {}, body = nil, status = 200, response_headers = {}, options: {} )
62
+ # @responses[Request.new(:post, path, nil, request_headers, options )] = Response.new(body || "", status, response_headers)
63
63
# end
64
64
module_eval <<-EOE , __FILE__ , __LINE__ + 1
65
- def #{ method } (path, request_headers = {}, body = nil, status = 200, response_headers = {})
66
- request = Request.new(:#{ method } , path, nil, request_headers)
65
+ def #{ method } (path, request_headers = {}, body = nil, status = 200, response_headers = {}, options = {} )
66
+ request = Request.new(:#{ method } , path, nil, request_headers, options )
67
67
response = Response.new(body || "", status, response_headers)
68
68
69
69
delete_duplicate_responses(request)
@@ -244,8 +244,8 @@ def net_connection_disabled?
244
244
{ true => %w( post patch put ) ,
245
245
false => %w( get delete head ) } . each do |has_body , methods |
246
246
methods . each do |method |
247
- # def post(path, body, headers)
248
- # request = ActiveResource::Request.new(:post, path, body, headers)
247
+ # def post(path, body, headers, options = {} )
248
+ # request = ActiveResource::Request.new(:post, path, body, headers, options )
249
249
# self.class.requests << request
250
250
# if response = self.class.responses.assoc(request)
251
251
# response[1]
@@ -254,8 +254,8 @@ def net_connection_disabled?
254
254
# end
255
255
# end
256
256
module_eval <<-EOE , __FILE__ , __LINE__ + 1
257
- def #{ method } (path, #{ 'body, ' if has_body } headers)
258
- request = ActiveResource::Request.new(:#{ method } , path, #{ has_body ? 'body, ' : 'nil, ' } headers)
257
+ def #{ method } (path, #{ 'body, ' if has_body } headers, options = {} )
258
+ request = ActiveResource::Request.new(:#{ method } , path, #{ has_body ? 'body, ' : 'nil, ' } headers, options )
259
259
self.class.requests << request
260
260
if response = self.class.responses.assoc(request)
261
261
response[1]
@@ -279,18 +279,29 @@ def inspect_responses # :nodoc:
279
279
class Request
280
280
attr_accessor :path , :method , :body , :headers
281
281
282
- def initialize ( method , path , body = nil , headers = { } )
283
- @method , @path , @body , @headers = method , path , body , headers
282
+ def initialize ( method , path , body = nil , headers = { } , options = { } )
283
+ @method , @path , @body , @headers , @options = method , path , body , headers , options
284
284
end
285
285
286
286
def ==( req )
287
- path == req . path && method == req . method && headers_match? ( req )
287
+ if @options && @options [ :omit_query_in_path ]
288
+ remove_query_params_from_path == req . remove_query_params_from_path && method == req . method && headers_match? ( req )
289
+ else
290
+ path == req . path && method == req . method && headers_match? ( req )
291
+ end
288
292
end
289
293
290
294
def to_s
291
295
"<#{ method . to_s . upcase } : #{ path } [#{ headers } ] (#{ body } )>"
292
296
end
293
297
298
+ # Removes query parameters from the path.
299
+ #
300
+ # @return [String] the path without query parameters
301
+ def remove_query_params_from_path
302
+ path . split ( "?" ) . first
303
+ end
304
+
294
305
private
295
306
def headers_match? ( req )
296
307
# Ignore format header on equality if it's not defined
0 commit comments