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 f1d7ae3cc1 Register inline sequence to allow for rewinding
This was originally opened as #1078, but this addresses the review
comments on that PR.

By registering the inline sequences, we allow them to get rewound with
`FactoryBot.rewind_sequences`. We register them with
`__#{factory_name}_#{sequence_name}__` to avoid conflicting with any
reasonably named global sequences, and to hint that we should not be
generating values from these sequences directly.

Co-authored-by: Damian Le Nouaille <dam@dln.name>
Co-authored-by: Damian Galarza <galarza.d@gmail.com>
2018-09-08 02:29:30 +00:00

37 lines
1.3 KiB
Ruby

module FactoryBot
# @api private
class Configuration
attr_reader :factories, :sequences, :traits, :strategies, :callback_names
attr_accessor :allow_class_lookup, :use_parent_strategy
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)
@allow_class_lookup = true
to_create { |instance| instance.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
def duplicate_attribute_assignment_from_initialize_with
false
end
def duplicate_attribute_assignment_from_initialize_with=(value)
ActiveSupport::Deprecation.warn 'Assignment of duplicate_attribute_assignment_from_initialize_with is unnecessary as this is now default behavior in FactoryBot 4.0; this line can be removed', caller
end
end
end