Skip to content

Commit

Permalink
Remove code duplication in ActiveResource::Request#==
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Jan 24, 2024
1 parent c7fc06f commit f11db24
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/active_resource/http_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,7 @@ def initialize(method, path, body = nil, headers = {}, options = {})
end

def ==(req)
if @options && @options[:omit_query_in_path]
remove_query_params_from_path == req.remove_query_params_from_path && method == req.method && headers_match?(req)
else
path == req.path && method == req.method && headers_match?(req)
end
same_path?(req) && method == req.method && headers_match?(req)
end

def to_s
Expand All @@ -303,6 +299,14 @@ def remove_query_params_from_path
end

private
def same_path(req)
if @options && @options[:omit_query_in_path]
remove_query_params_from_path == req.remove_query_params_from_path
else
path == req.path
end
end

def headers_match?(req)
# Ignore format header on equality if it's not defined
format_header = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[method]
Expand Down

0 comments on commit f11db24

Please sign in to comment.