mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
0f4b404569
This commit deprecates several undocumented top-level FactoryBot methods: * callbacks * configuration * constructor * initialize_with * register_sequence * resent_configuration * skip_create * to_create factory_bot users are not meant to access these methods directly. Instead they are available for internal use through the new Internal module introduced in #1262. --- While addressing the new deprecation warnings, I tried to make the delegation a bit more consistent, always delegating to `FactoryBot::Internal`. This involved requiring "factory_bot/internal" sooner. To avoid having to fight with the order of requires and potential circular dependencies, I moved the default strategy and callback registration out of constants (this is how they used to be before #1297), so it doesn't matter if those strategies are loaded before the `Internal` module. I also deleted a pair of tests that were using these constants - these strategies and callbacks are covered elsewhere in our test suite, and I don't think these tests were adding much value (they missed #1379, for example).
38 lines
872 B
Ruby
38 lines
872 B
Ruby
module FactoryBot
|
|
class DefinitionHierarchy
|
|
delegate :callbacks, :constructor, :to_create, to: Internal
|
|
|
|
def self.build_from_definition(definition)
|
|
build_to_create(&definition.to_create)
|
|
build_constructor(&definition.constructor)
|
|
add_callbacks definition.callbacks
|
|
end
|
|
|
|
def self.add_callbacks(callbacks)
|
|
if callbacks.any?
|
|
define_method :callbacks do
|
|
super() + callbacks
|
|
end
|
|
end
|
|
end
|
|
private_class_method :add_callbacks
|
|
|
|
def self.build_constructor(&block)
|
|
if block
|
|
define_method(:constructor) do
|
|
block
|
|
end
|
|
end
|
|
end
|
|
private_class_method :build_constructor
|
|
|
|
def self.build_to_create(&block)
|
|
if block
|
|
define_method(:to_create) do
|
|
block
|
|
end
|
|
end
|
|
end
|
|
private_class_method :build_to_create
|
|
end
|
|
end
|