Skip to content

DTT (Staging > Test) [robo-dtt] - #51445

Merged
deploy-code-org merged 9 commits into
testfrom
staging
Apr 20, 2023
Merged

DTT (Staging > Test) [robo-dtt]#51445
deploy-code-org merged 9 commits into
testfrom
staging

Conversation

@deploy-code-org

Copy link
Copy Markdown
Contributor

No description provided.

Hamms added 9 commits April 13, 2023 17:55
In preparation for an update to FactoryBot 5, which fixes some unintuitive behavior when `build`ing objects with descendents. Specifically, the `:pd_teacher_application` factory calls `build :pd_teacher_application_hash_common` which in turn calls `association :school`; right now, even though the Hash is being called with `build` rather than `create`, that `School` object still gets persisted. In fact, that behavior is *required* since we pass the `id` of the `School` object upstream to the `:pd_teacher_application` factory which as part of its own persistence logic expects its `school_id` attribute to reference a persisted object.

Startingin FactoryBot 5, the default association strategy will now be inherited from the parent factory, so `build`ing a hash will `build` but not persist the associated `School` object. In most cases this is probably desirable, but here we are relying on the old strange behavior and so now need to explicitly specify that we always want to persist the associated `School` object.

https://github.com/thoughtbot/factory_bot/blob/main/GETTING_STARTED.md#build-strategies-1
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 record are often automatically persisted upon creation. Starting in v5, we are much more likely to encounter this edge case, so in anticipation of updating to that version we change the generation logic to use unique emails rather than attempting to enforce an arbitrary sequence.
…so that its associated records are also persisted and able to be validated
Generate Random Rather than Sequential Test Emails
Consistently Persist PD FactoryBot Records in v5
@deploy-code-org
deploy-code-org merged commit baf8b3f into test Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants