New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shorten inspect on ActionDispatch::Request #40173
Conversation
assert_match %r(#<ActionDispatch::Request method="POST"), request.inspect | ||
assert_match %r(original_url="https://glu.ttono.us/path/of/some/uri\?mapped=1"), request.inspect | ||
assert_match %r(remote_ip="1.2.3.4"), request.inspect | ||
assert_match %r(media_type="application/x-www-form-urlencoded">), request.inspect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_match %r(#<ActionDispatch::Request method="POST"), request.inspect | |
assert_match %r(original_url="https://glu.ttono.us/path/of/some/uri\?mapped=1"), request.inspect | |
assert_match %r(remote_ip="1.2.3.4"), request.inspect | |
assert_match %r(media_type="application/x-www-form-urlencoded">), request.inspect | |
assert_equal '#<ActionDispatch::Request method="POST", original_url="https://glu.ttono.us/path/of/some/uri?mapped=1", remote_ip="1.2.3.4", media_type="application/x-www-form-urlencoded">', request.inspect |
Small suggestion but I think we can just test the entire string without having to regexp match on parts of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's kind of long. Maybe the output of inspect can be shortened to just:
#<ActionDispatch::Request POST "https://glu.ttono.us/path/of/some/uri?mapped=1">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tgxworld I've shortend the output to same format as used for requests in the logs. This also allows the assertion to use a single line without getting to long.
"#<ActionDispatch::Request POST "https://example.com/path/of/some/uri?q=1" for 1.2.3.4>"
Calling request in an action of a controller generates an endless stream of characters, including the Rack app and middlewares. This can be frustrating when using a debugger in a controller and accidentally calling `request` generates output for a couple of seconds. Inspect on ActionDispatch::Request is shortened to the most relevant attributes and uses the same format as used for request in the logs: "#<ActionDispatch::Request POST "https://example.com/path/of/some/uri?q=1" for 1.2.3.4>"
Summary
Calling
request
in an action of a controller generates an endless stream ofcharacters, including the Rack app and middlewares.
This can be frustrating when using a debugger in a controller and
accidentally calling
request
generates output for a couple of seconds.Inspect on ActionDispatch::Request is shortened to relevant attributes:
Other Information
This pull request splits an older pull request into two separate pull requests.
#39439
Edit:
I've changed the output to use the same format as used for requests in the logs: