Created
September 3, 2024 23:06
-
-
Save elias19r/9461500f93f533e2520a0ba8e22eaed4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class TestRequestHelper | |
def self.build( | |
method: 'GET', | |
url: 'http://test.upper.town/', | |
params: {}, | |
headers: {}, | |
env: {}, | |
remote_ip: '1.1.1.1', | |
referer: nil | |
) | |
request_env = Rack::MockRequest.env_for(url, { | |
'REQUEST_METHOD' => method, | |
'REMOTE_ADDR' => remote_ip, | |
'HTTP_REFERER' => referer, | |
}.compact) | |
request_env['HTTP_HOST'] = "#{request_env['SERVER_NAME']}:#{request_env['SERVER_PORT']}" | |
request = ActionDispatch::TestRequest.create(request_env) | |
request.params.merge!(params) | |
request.headers.merge!(headers) | |
request.headers.merge!(env) | |
request | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment