Browse files

Add a before_create callback

Closes #323
  • Loading branch information...
1 parent 4e2a672 commit 24d417d5754a82a796bc45f0bf765df844c8d206 @joshuaclayton joshuaclayton committed Mar 30, 2012
Showing with 3 additions and 2 deletions.
  1. +1 −1 lib/factory_girl.rb
  2. +1 −0 lib/factory_girl/strategy/create.rb
  3. +1 −1 spec/factory_girl/strategy/create_spec.rb
View
2 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
View
1 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
View
2 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

0 comments on commit 24d417d

Please sign in to comment.