Adds traits as mixins to 'Getting started' (#1521)
This commit is contained in:
parent
1b81d5dc25
commit
dc65e786a9
|
@ -1196,6 +1196,28 @@ factory :user do
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### As mixins
|
||||||
|
|
||||||
|
Traits can be defined outside of factories and used as mixins to compose shared attributes
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
FactoryBot.define do
|
||||||
|
trait :timestamps do
|
||||||
|
created_at { 8.days.ago }
|
||||||
|
updated_at { 4.days.ago }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :user, traits: [:timestamps] do
|
||||||
|
username { "john_doe" }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :post do
|
||||||
|
timestamps
|
||||||
|
title { "Traits rock" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
### Using traits
|
### Using traits
|
||||||
|
|
||||||
Traits can also be passed in as a list of symbols when you construct an instance
|
Traits can also be passed in as a list of symbols when you construct an instance
|
||||||
|
|
Loading…
Reference in New Issue