Traits
Let's flesh out our user model a little:
We've implemented email verification so users have a
verified
flag indicating whether their email has been verifiedAfter some of our admins were harassed we've decided to give their accounts anonymized email addresses
We've also noticed that we're writing tests for users more frequently, so we want to change the default role in the factory to "user"
Now our email key is linked to the role of the user, so we might want to control these two together. We can use traits
to do this. Traits are like little snippets of a template we can control with a single keyword. Let's update our factory definition a little:
We've added a traits
key to the factory definition, and added two traits admin
and unverified
. Now we can use the traits as shorthand when we build by specifying them in the build options:
Traits can be composed:
Last updated