factory_bot icon indicating copy to clipboard operation
factory_bot copied to clipboard

[1452] update traits_for_enum to accept _prefix and _suffix

Open tjbarker opened this issue 2 years ago • 2 comments

in response to Issue.

goal is to allow _prefix and _suffix for enum trait definitions to stay in line with ruby implementations also will not define the standard enum (without prefix/suffix) will only define the ones with prefix/suffix

tjbarker avatar Sep 20 '21 06:09 tjbarker

I came just to report this issue but it already exists, yay!

Glad to see work addressing it. Though as a user, I wouldn't be excited the current implementation requires duplicating the enum configuration in both the model and the factory. I would have expected that the factory "inherits" the enum configuration from the model itself. Otherwise, the prefix/suffix config could drift from what is defined in the model.

jasonkarns avatar Sep 20 '21 21:09 jasonkarns

Hey jasonkarns.

not wanting to replicate enum config in factories and models makes sense. This implementation was chosen because the flip side of explicitly setting these values would require hooking into active record which currently does not store or make available enough information to build this out.

my reasoning for thinking it wouldn’t be that bad to use this is:

  • the factory only needs to define the enum and prefix/suffix. If you are inheriting the enum list from the model then it will continue to inherit. Change in model enums are usually due to adding values which would automatically be added to the factory’s trait list, it’s not often that the enum attribute name or prefix/suffix change
  • this will only be needed for enums with a prefix/suffix. Most enums don’t have these so will continue to be automatically added as traits to factories

tjbarker avatar Sep 20 '21 22:09 tjbarker