Skip to content
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

AO3-6439 Set User.current_user in around_action hook and fix tests using it outside of requests #5111

Conversation

Bilka2
Copy link
Contributor

@Bilka2 Bilka2 commented Mar 24, 2025

Issue

https://otwarchive.atlassian.net/browse/AO3-6439

Purpose

Moves setting User.current_user to an around_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 for User.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 the paths.rb file. Unfortunately, the only way to remove references to the currently logged in user in paths.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

@Bilka2 Bilka2 force-pushed the AO3-6439-set-user-current-user-in-an-around-action-hook branch from 16d7a78 to 26c8583 Compare March 24, 2025 13:54
Copy link
Member

@brianjaustin brianjaustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! (I was going to suggest some wording changes to the step names, but since most of them exist already I would rather control scope for this PR and do that later)

@brianjaustin brianjaustin merged commit fe56094 into otwcode:master Mar 26, 2025
29 checks passed
@Bilka2 Bilka2 deleted the AO3-6439-set-user-current-user-in-an-around-action-hook branch March 26, 2025 20:04
Copy link

sentry-io bot commented Mar 26, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants