@@ -58,12 +58,12 @@ def initialize(responses)
5858 end
5959
6060 [ :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)
6363 # end
6464 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 )
6767 response = Response.new(body || "", status, response_headers)
6868
6969 delete_duplicate_responses(request)
@@ -244,8 +244,8 @@ def net_connection_disabled?
244244 { true => %w( post patch put ) ,
245245 false => %w( get delete head ) } . each do |has_body , methods |
246246 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 )
249249 # self.class.requests << request
250250 # if response = self.class.responses.assoc(request)
251251 # response[1]
@@ -254,8 +254,8 @@ def net_connection_disabled?
254254 # end
255255 # end
256256 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 )
259259 self.class.requests << request
260260 if response = self.class.responses.assoc(request)
261261 response[1]
@@ -279,18 +279,29 @@ def inspect_responses # :nodoc:
279279 class Request
280280 attr_accessor :path , :method , :body , :headers
281281
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
284284 end
285285
286286 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
288292 end
289293
290294 def to_s
291295 "<#{ method . to_s . upcase } : #{ path } [#{ headers } ] (#{ body } )>"
292296 end
293297
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+
294305 private
295306 def headers_match? ( req )
296307 # Ignore format header on equality if it's not defined
0 commit comments