mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Simplify #build_hierarchy
This commit is contained in:
parent
e3e9ce6968
commit
82208a1008
2 changed files with 10 additions and 3 deletions
|
@ -12,6 +12,12 @@ module FactoryGirl
|
||||||
FactoryGirl.to_create
|
FactoryGirl.to_create
|
||||||
end
|
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)
|
def self.add_callbacks(callbacks)
|
||||||
if callbacks.any?
|
if callbacks.any?
|
||||||
define_method :callbacks do
|
define_method :callbacks do
|
||||||
|
@ -19,6 +25,7 @@ module FactoryGirl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
private_class_method :add_callbacks
|
||||||
|
|
||||||
def self.build_constructor(&block)
|
def self.build_constructor(&block)
|
||||||
if block
|
if block
|
||||||
|
@ -27,6 +34,7 @@ module FactoryGirl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
private_class_method :build_constructor
|
||||||
|
|
||||||
def self.build_to_create(&block)
|
def self.build_to_create(&block)
|
||||||
if block
|
if block
|
||||||
|
@ -35,5 +43,6 @@ module FactoryGirl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
private_class_method :build_to_create
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -121,9 +121,7 @@ module FactoryGirl
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_hierarchy
|
def build_hierarchy
|
||||||
hierarchy_class.build_to_create &definition.to_create
|
hierarchy_class.build_from_definition definition
|
||||||
hierarchy_class.build_constructor &definition.constructor
|
|
||||||
hierarchy_class.add_callbacks definition.callbacks
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def callbacks
|
def callbacks
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue