factory_bot: clarify ways to build

This commit is contained in:
Rico Sta. Cruz 2017-10-30 00:16:30 +08:00
parent 5f1d4265eb
commit 9c1c638048
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 11 additions and 5 deletions

View File

@ -54,24 +54,30 @@ end
### Using
#### Build a model
```ruby
FactoryBot.build(:user)
```
#### Other ways
```ruby
build(:user) # not saved
create(:user) # saved
attributes_for(:user) # hash
build(:user) # → model (not saved)
create(:user) # → model (saved)
attributes_for(:user) # hash
build_stubbed(:user) # stubbed out attributes
```
#### With options
```ruby
# With options:
build(:user, name: 'John')
```
#### Lists
```ruby
# List:
create_list(:user, 3)
build_list(:user, 3)
```