You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We use a slightly unconventional ID scheme in our DB. Rather than the usual auto-incrementing IDs or UUIDs, we use string IDs like those found in Stripe's API. (Basically our IDs look like <prefix>_<uuid> where prefix is unique to each model class, but that's not relevant to the request.)
Today, FactoryBot only supports auto-incrementing IDs or UUIDs when building stubbed models.
Desired solution
It would be great if there was a way to provide a callable to FactoryBot to be used to generate IDs for stubbed models. What I had in mind was something like this:
Problem this feature will solve
We use a slightly unconventional ID scheme in our DB. Rather than the usual auto-incrementing IDs or UUIDs, we use string IDs like those found in Stripe's API. (Basically our IDs look like
<prefix>_<uuid>
whereprefix
is unique to each model class, but that's not relevant to the request.)Today, FactoryBot only supports auto-incrementing IDs or UUIDs when building stubbed models.
Desired solution
It would be great if there was a way to provide a callable to FactoryBot to be used to generate IDs for stubbed models. What I had in mind was something like this:
FactoryBot would use the ID factory if it's defined and returns a non-nil result, or fall back to the current behavior otherwise.
Alternatives considered
Right now we're directly patching FactoryBot, but that's obviously not great.
Here's our patch FWIW:
Additional context
I'm happy to submit a PR for this feature if you think it would be a nice addition to the gem.
The text was updated successfully, but these errors were encountered: