mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Improve documentation around implicit attributes
[skip ci] Closes #1017
This commit is contained in:
parent
cffa56e4c8
commit
6afa639804
2 changed files with 14 additions and 5 deletions
|
@ -541,6 +541,9 @@ factory :user do
|
|||
end
|
||||
```
|
||||
|
||||
Note that defining sequences as implicit attributes will not work if you have a
|
||||
factory with the same name as the sequence.
|
||||
|
||||
And it's also possible to define an in-line sequence that is only used in
|
||||
a particular factory:
|
||||
|
||||
|
@ -649,7 +652,7 @@ factory :story do
|
|||
end
|
||||
```
|
||||
|
||||
Traits can be used as attributes:
|
||||
Traits can be used as implicit attributes:
|
||||
|
||||
```ruby
|
||||
factory :week_long_published_story_with_title, parent: :story do
|
||||
|
@ -659,6 +662,9 @@ factory :week_long_published_story_with_title, parent: :story do
|
|||
end
|
||||
```
|
||||
|
||||
Note that defining traits as implicit attributes will not work if you have a
|
||||
factory or sequence with the same name as the trait.
|
||||
|
||||
Traits that define the same attributes won't raise AttributeDefinitionErrors;
|
||||
the trait that defines the attribute latest gets precedence.
|
||||
|
||||
|
|
|
@ -56,17 +56,20 @@ module FactoryBot
|
|||
#
|
||||
# are equivalent.
|
||||
#
|
||||
# If no argument or block is given, factory_bot will look for a sequence
|
||||
# or association with the same name. This means that:
|
||||
# If no argument or block is given, factory_bot will first look for an
|
||||
# association, then for a sequence, and finally for a trait with the same
|
||||
# name. This means that given an "admin" trait, an "email" sequence, and an
|
||||
# "account" factory:
|
||||
#
|
||||
# factory :user do
|
||||
# email { create(:email) }
|
||||
# factory :user, traits: [:admin] do
|
||||
# email { generate(:email) }
|
||||
# association :account
|
||||
# end
|
||||
#
|
||||
# and:
|
||||
#
|
||||
# factory :user do
|
||||
# admin
|
||||
# email
|
||||
# account
|
||||
# end
|
||||
|
|
Loading…
Add table
Reference in a new issue