Methods
- accept=
- action=
- create
- host=
- if_modified_since=
- if_none_match=
- path=
- port=
- remote_addr=
- request_method=
- request_uri=
- user_agent=
Constants
DEFAULT_ENV | = | Rack::MockRequest.env_for("/", "HTTP_HOST" => "test.host".b, "REMOTE_ADDR" => "0.0.0.0".b, "HTTP_USER_AGENT" => "Rails Testing".b, ) |
Class Public methods
create(env = {})
Create a new test request with default env
values.
📝 Source code
# File actionpack/lib/action_dispatch/testing/test_request.rb, line 17
def self.create(env = {})
env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
env["rack.request.cookie_hash"] ||= {}.with_indifferent_access
new(default_env.merge(env))
end
🔎 See on GitHub
Instance Public methods
accept=(mime_types)
📝 Source code
# File actionpack/lib/action_dispatch/testing/test_request.rb, line 68
def accept=(mime_types)
delete_header("action_dispatch.request.accepts")
set_header("HTTP_ACCEPT", Array(mime_types).collect(&:to_s).join(","))
end
🔎 See on GitHub
action=(action_name)
📝 Source code
# File actionpack/lib/action_dispatch/testing/test_request.rb, line 48
def action=(action_name)
path_parameters[:action] = action_name.to_s
end
🔎 See on GitHub
host=(host)
📝 Source code
# File actionpack/lib/action_dispatch/testing/test_request.rb, line 32
def host=(host)
set_header("HTTP_HOST", host)
end
🔎 See on GitHub
if_modified_since=(last_modified)
📝 Source code
# File actionpack/lib/action_dispatch/testing/test_request.rb, line 52
def if_modified_since=(last_modified)
set_header("HTTP_IF_MODIFIED_SINCE", last_modified)
end
🔎 See on GitHub
if_none_match=(etag)
📝 Source code
# File actionpack/lib/action_dispatch/testing/test_request.rb, line 56
def if_none_match=(etag)
set_header("HTTP_IF_NONE_MATCH", etag)
end
🔎 See on GitHub
path=(path)
📝 Source code
# File actionpack/lib/action_dispatch/testing/test_request.rb, line 44
def path=(path)
set_header("PATH_INFO", path)
end
🔎 See on GitHub
port=(number)
📝 Source code
# File actionpack/lib/action_dispatch/testing/test_request.rb, line 36
def port=(number)
set_header("SERVER_PORT", number)
end
🔎 See on GitHub
remote_addr=(addr)
📝 Source code
# File actionpack/lib/action_dispatch/testing/test_request.rb, line 60
def remote_addr=(addr)
set_header("REMOTE_ADDR", addr)
end
🔎 See on GitHub
request_method=(method)
📝 Source code
# File actionpack/lib/action_dispatch/testing/test_request.rb, line 28
def request_method=(method)
super(method.to_s.upcase)
end
🔎 See on GitHub
request_uri=(uri)
📝 Source code
# File actionpack/lib/action_dispatch/testing/test_request.rb, line 40
def request_uri=(uri)
set_header("REQUEST_URI", uri)
end
🔎 See on GitHub
user_agent=(user_agent)
📝 Source code
# File actionpack/lib/action_dispatch/testing/test_request.rb, line 64
def user_agent=(user_agent)
set_header("HTTP_USER_AGENT", user_agent)
end
🔎 See on GitHub