Deprecate *_via_redirect integration test methods - #18693
Conversation
|
In the deprecation, we should just add "Please use follow_redirect! manually after the request call for the same behavior." |
There was a problem hiding this comment.
Instead of adding new tests, you can wrap assert_deprecated around existing test assertions. I think this will also prevent the existing tests from spamming deprecation text in the test log.
4b2b953 to
f07cd8b
Compare
|
@aditya-kapoor looks OK although usually you'd try reducing |
There was a problem hiding this comment.
The message should be:
get_via_redirect is deprecated and will be removed in the next version of Rails. Please use follow_redirect! manually after the request call for the same behavior.
|
Also remove the whitespaces changes in the patch. |
f07cd8b to
751f752
Compare
|
@rafaelfranca done... |
|
Merging |
Deprecate *_via_redirect integration test methods
|
I like to use |
|
What are you using the integration_test? check for?
|
|
I define a |
|
Ah, I think maybe having separate helpers when they do separate things is a better deal than multiple paths inside a single method. But curious to see the implementation!
|
|
The # Logs in a test user.
def log_in_as(user, options = {})
password = options[:password] || 'password'
remember_me = options[:remember_me] || '1'
if integration_test?
post login_path, session: { email: user.email,
password: password,
remember_me: remember_me }
else
session[:user_id] = user.id
end
end
private
# Returns true inside an integration test.
def integration_test?
defined?(post_via_redirect)
end(Come to think of it, the definitions of |
|
These two paths share almost nothing. Not even the signature. I would split them out. Much clearer, imo: # Logs in a test user.
def log_in_as(user, password: 'password', remember_me: '1')
post login_path, session: { email: user.email,
password: password,
remember_me: remember_me }
end
def log_in_as(user)
session[:user_id] = user.id
end |
|
In fact, I would also rename them to follow the intent. The integration helper is legitimately |
|
I appreciate the feedback and will consider incorporating it in future refinements of the tutorial. In the mean time, does anyone have any suggestions for writing an |
|
If you don't care about the implementation, you can just do |
|
Consider separate implementations in the controller and integration test classes: class ActionDispatch::IntegrationTest
def log_in_as(user, password: 'password', remember_me: '1')
post login_path, session: {
email: user.email,
password: password,
remember_me: remember_me
}
end
end
class ActionController::TestCase
def log_in_as(user)
session[:user_id] = user.id
end
end |
|
@georgeclaghorn Cool, thanks for the suggestion. |
- Followup of rails#18693. - I think we missed deprecating `request_via_redirect` in that pull request. - Originally requested by DHH here rails#18333.
As asked by @dhh in #18333.
Closes #18333.