AO3-6439 Set User.current_user in around_action hook and fix tests using it outside of requests #5111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
https://otwarchive.atlassian.net/browse/AO3-6439
Purpose
Moves setting
User.current_user
to anaround_action
hook. This means it's consistently cleared outside of requests. This relevant for tests, where can be code running outside of request which would erroneously have the previous value set forUser.current_user
.Because
User.current_user
is no longer set outside requests, all test steps that relied on it being set needed to modified. This was various steps and the crucially also thepaths.rb
file. Unfortunately, the only way to remove references to the currently logged in user inpaths.rb
is to directly reference a user by name, which means modifying all the path names. This lead to a lot of cascading changes around the tests. My apologies to whoever reviews this, but it wasn't possible to split it into multiple commits.After this fix, various test steps no longer need to force
User.current_user
to be nil before using FactoryBot, so I've removed those lines.This should hopefully fix the flaky tests we've seen recently. At least some of them were definitely related to
User.current_user
unexpectedly being nil outside requests. Now that it's always nil and the tests have been adjusted, this should no longer be an issue.Testing Instructions
For manual testing, refer to Jira.
For automated testing, I reran the automated tests 3 times and they were not flaky: https://github.com/Bilka2/otwarchive/actions/runs/14035346539
Credit
Bilka