1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/lib/factory_bot/configuration.rb
Daniel Colson 3e1a941347 Do not reset use_parent_strategy on reload
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.
2019-01-04 15:47:32 -05:00

25 lines
843 B
Ruby

module FactoryBot
# @api private
class Configuration
attr_reader :factories, :sequences, :traits, :strategies, :callback_names
def initialize
@factories = Decorator::DisallowsDuplicatesRegistry.new(Registry.new("Factory"))
@sequences = Decorator::DisallowsDuplicatesRegistry.new(Registry.new("Sequence"))
@traits = Decorator::DisallowsDuplicatesRegistry.new(Registry.new("Trait"))
@strategies = Registry.new("Strategy")
@callback_names = Set.new
@definition = Definition.new(:configuration)
to_create(&:save!)
initialize_with { new }
end
delegate :to_create, :skip_create, :constructor, :before, :after,
:callback, :callbacks, to: :@definition
def initialize_with(&block)
@definition.define_constructor(&block)
end
end
end