Skip to content

Commit

Permalink
Adds traits as mixins to 'Getting started' (#1521)
Browse files Browse the repository at this point in the history
  • Loading branch information
eikes authored Mar 8, 2022
1 parent 1b81d5d commit dc65e78
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,28 @@ factory :user do
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

Traits can also be passed in as a list of symbols when you construct an instance
Expand Down

0 comments on commit dc65e78

Please sign in to comment.