Before this PR, `use_parent_strategy` was set on the configuration
instance. Since `FactoryBot.reload` wipes out the configuration, it also
ends up resetting `use_parent_strategy` back to `nil`.
This can cause problems when using factory_bot_rails with Spring, since
it calls `FactoryBot.reload` each time Spring forks. If
`use_parent_strategy` is set in a file that Spring preloads, like in an
initializer, then the value will get wiped out.
With this PR, we set `use_parent_strategy` directly on FactoryBot,
rather than on the configuration instance, and so reloading no longer
has any effect.
This change means that:
1. The option is turned on, and
2. A Post has a User (for example), and
3. We build an association
4. Then the User is built too.
With the flag off, the User would be created, which matches current
behaviour.
See: https://github.com/thoughtbot/factory_girl/pull/749
In the following example, `FactoryGirl.create(:order)` returns 0 because the last expression returns 0.
`:order` is set to 0 causing an unexpected behavior.
let(:order) {
FactoryGirl.create(:order) do |order|
order.save!
order.total_cents = 0
end
}
order
# => 0