Add per model automatically_define_enum_traits option #1598
+94
−7
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.
Currently you can only specify whether to automatically define enum traits at a global level, through
FactoryBot.automatically_define_enum_traits
. This means that an entire codebase has to either opt-in, or opt-out from automatically defining enum traits. If you are in a large, established codebase with lots of enum's, this is quite hard to change globally when you find that automatically defining them doesn't fit for your new use case.If we could override this at a per-factory level, we could allow individual factories to override the global setting where appropriate, in order to do customise them where necessary.
Given
FactoryBot.automatically_define_enum_traits
being set totrue
, and a model calledTask
with the following enum definition:You would be able to override disable this on a per-factory basis like so:
If
FactoryBot.automatically_define_enum_traits
was instead set tofalse
, then the same model with a factory override set totrue
you would end up with the following automatic traits:Fixes: #1597