From f11db24fa0e9ef206560ff1768c2fe4acc5488b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 24 Jan 2024 20:05:41 +0000 Subject: [PATCH] Remove code duplication in ActiveResource::Request#== --- lib/active_resource/http_mock.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/active_resource/http_mock.rb b/lib/active_resource/http_mock.rb index ac38833597..625fa05e05 100644 --- a/lib/active_resource/http_mock.rb +++ b/lib/active_resource/http_mock.rb @@ -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 @@ -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]