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
|
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
|
And it's also possible to define an in-line sequence that is only used in
|
||||||
a particular factory:
|
a particular factory:
|
||||||
|
|
||||||
|
@ -649,7 +652,7 @@ factory :story do
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Traits can be used as attributes:
|
Traits can be used as implicit attributes:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
factory :week_long_published_story_with_title, parent: :story do
|
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
|
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;
|
Traits that define the same attributes won't raise AttributeDefinitionErrors;
|
||||||
the trait that defines the attribute latest gets precedence.
|
the trait that defines the attribute latest gets precedence.
|
||||||
|
|
||||||
|
|
|
@ -56,17 +56,20 @@ module FactoryBot
|
||||||
#
|
#
|
||||||
# are equivalent.
|
# are equivalent.
|
||||||
#
|
#
|
||||||
# If no argument or block is given, factory_bot will look for a sequence
|
# If no argument or block is given, factory_bot will first look for an
|
||||||
# or association with the same name. This means that:
|
# 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
|
# factory :user, traits: [:admin] do
|
||||||
# email { create(:email) }
|
# email { generate(:email) }
|
||||||
# association :account
|
# association :account
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# and:
|
# and:
|
||||||
#
|
#
|
||||||
# factory :user do
|
# factory :user do
|
||||||
|
# admin
|
||||||
# email
|
# email
|
||||||
# account
|
# account
|
||||||
# end
|
# end
|
||||||
|
|
Loading…
Reference in a new issue