Add a before_create callback

Closes #323
This commit is contained in:
Joshua Clayton 2012-03-30 12:01:51 -04:00
parent 4e2a672b9e
commit 24d417d575
3 changed files with 3 additions and 2 deletions

View File

@ -64,6 +64,6 @@ module FactoryGirl
end
def self.callback_names
[:after_build, :after_create, :after_stub].freeze
[:after_build, :after_create, :after_stub, :before_create].freeze
end
end

View File

@ -8,6 +8,7 @@ module FactoryGirl
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

View File

@ -2,7 +2,7 @@ require 'spec_helper'
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