From 82208a100862cacb9a023e404ab33bf4f1861ae8 Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Fri, 14 Sep 2012 08:22:28 -0400 Subject: [PATCH] Simplify #build_hierarchy --- lib/factory_girl/definition_hierarchy.rb | 9 +++++++++ lib/factory_girl/factory.rb | 4 +--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/factory_girl/definition_hierarchy.rb b/lib/factory_girl/definition_hierarchy.rb index 110de8d..6b755af 100644 --- a/lib/factory_girl/definition_hierarchy.rb +++ b/lib/factory_girl/definition_hierarchy.rb @@ -12,6 +12,12 @@ module FactoryGirl FactoryGirl.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 @@ -19,6 +25,7 @@ module FactoryGirl end end end + private_class_method :add_callbacks def self.build_constructor(&block) if block @@ -27,6 +34,7 @@ module FactoryGirl end end end + private_class_method :build_constructor def self.build_to_create(&block) if block @@ -35,5 +43,6 @@ module FactoryGirl end end end + private_class_method :build_to_create end end diff --git a/lib/factory_girl/factory.rb b/lib/factory_girl/factory.rb index 133a272..c7a4422 100644 --- a/lib/factory_girl/factory.rb +++ b/lib/factory_girl/factory.rb @@ -121,9 +121,7 @@ module FactoryGirl end def build_hierarchy - hierarchy_class.build_to_create &definition.to_create - hierarchy_class.build_constructor &definition.constructor - hierarchy_class.add_callbacks definition.callbacks + hierarchy_class.build_from_definition definition end def callbacks