diff --git a/lib/factory_girl.rb b/lib/factory_girl.rb index 7754499f5..a13325fec 100644 --- a/lib/factory_girl.rb +++ b/lib/factory_girl.rb @@ -64,6 +64,6 @@ def self.trait_by_name(name) end def self.callback_names - [:after_build, :after_create, :after_stub].freeze + [:after_build, :after_create, :after_stub, :before_create].freeze end end diff --git a/lib/factory_girl/strategy/create.rb b/lib/factory_girl/strategy/create.rb index 4cf2be192..055120883 100644 --- a/lib/factory_girl/strategy/create.rb +++ b/lib/factory_girl/strategy/create.rb @@ -8,6 +8,7 @@ def association(runner) def result(attribute_assigner, to_create) attribute_assigner.object.tap do |result_instance| run_callbacks(:after_build, result_instance) + run_callbacks(:before_create, result_instance) to_create[result_instance] run_callbacks(:after_create, result_instance) end diff --git a/spec/factory_girl/strategy/create_spec.rb b/spec/factory_girl/strategy/create_spec.rb index 5db5b5ea6..a124774ea 100644 --- a/spec/factory_girl/strategy/create_spec.rb +++ b/spec/factory_girl/strategy/create_spec.rb @@ -2,7 +2,7 @@ describe FactoryGirl::Strategy::Create do it_should_behave_like "strategy with association support", FactoryGirl::Strategy::Create - it_should_behave_like "strategy with callbacks", :after_build, :after_create + it_should_behave_like "strategy with callbacks", :after_build, :before_create, :after_create it "runs a custom create block" do block_run = false