mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
c716ce01b4
Also: add a deprecation warning to factory_girl, asking users to switch to factory_bot https://github.com/thoughtbot/factory_girl/issues/921
48 lines
973 B
Ruby
48 lines
973 B
Ruby
module FactoryBot
|
|
class DefinitionHierarchy
|
|
def callbacks
|
|
FactoryBot.callbacks
|
|
end
|
|
|
|
def constructor
|
|
FactoryBot.constructor
|
|
end
|
|
|
|
def to_create
|
|
FactoryBot.to_create
|
|
end
|
|
|
|
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
|