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 79331a3863 Allow inline sequences in traits to have same name
Fixes #1257

When sequence rewinding was first introduced in #1078 it only applied to
globally defined sequences. To get rewinding to work for inline
sequences as well we registered them "privately" in the global registry
in #1164. Unfortunately in #1164 we did not take inline sequences inside
traits into consideration. Since trait names are not unique, it is
possibly to get a `FactoryBot::DuplicateDefinitionError` when defining
two sequences that have the same name in two traits that have the same
name.

This PR abandons the idea of "privately" registering inline sequences,
and instead keeps a separate list of all the inline sequences just for
the purpose of rewinding them.
2019-02-15 17:10:27 -05:00

33 lines
935 B
Ruby

module FactoryBot
# @api private
class Configuration
attr_reader(
:callback_names,
:factories,
:inline_sequences,
:sequences,
:strategies,
:traits,
)
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)
@inline_sequences = []
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