... | @@ -137,6 +137,14 @@ user.role_text # User's manager |
... | @@ -137,6 +137,14 @@ user.role_text # User's manager |
|
Enum::Roles.manager.text # Manager
|
|
Enum::Roles.manager.text # Manager
|
|
```
|
|
```
|
|
|
|
|
|
|
|
#### Scopes
|
|
|
|
|
|
|
|
For each value, the model where the enum was defined receives additional scopes, making it easy to filter records.
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
User.manager # SELECT * FROM "users" WHERE "users"."role" = 'manager'
|
|
|
|
```
|
|
|
|
|
|
### Testing
|
|
### Testing
|
|
|
|
|
|
When testing models or creating records using factories, `Enum` provides an easy way to get a random value from the list of any enum types. Besides the normal `User.roles.sample`, you can also use:
|
|
When testing models or creating records using factories, `Enum` provides an easy way to get a random value from the list of any enum types. Besides the normal `User.roles.sample`, you can also use:
|
... | | ... | |