Generate Random Rather than Sequential Test Emails #51400
Merged
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.
We expect emails to be globally unique, but the method we currently use to generate test emails for facilitators and workshop organizers means that multiple calls to
build :workshop_organizer
will result in the same email being generated for each user, which will cause an error if we attempt to persist both of them.This isn't a problem right now, because some unexpected behavior in FactoryBot v4 means that records are often automatically persisted upon creation. Starting in v5, we are much more likely to encounter the edge case of multiple records being initially built but not persisted only for a subset of them to be persisted after the fact. In anticipation of updating to that version, we change the generation logic to use unique emails rather than attempting to enforce an arbitrary sequence.
Links
I did some digging into the history of this email generation logic, and couldn't find any evidence that we cared about the sequential nature of the old approach; it seemed like we were just going with the simplest, cleanest option in the absence of a need for anything this complicated.
Testing story
Verified on another branch that this change resolves the issues with FactoryBot v5.
Follow-up work
Upgrade FactoryBot to v5