Skip to content
This repository
Browse code

Add a before_create callback

Closes #323
  • Loading branch information...
commit 24d417d5754a82a796bc45f0bf765df844c8d206 1 parent 4e2a672
Joshua Clayton authored March 30, 2012
2  lib/factory_girl.rb
@@ -64,6 +64,6 @@ def self.trait_by_name(name)
64 64
   end
65 65
 
66 66
   def self.callback_names
67  
-    [:after_build, :after_create, :after_stub].freeze
  67
+    [:after_build, :after_create, :after_stub, :before_create].freeze
68 68
   end
69 69
 end
1  lib/factory_girl/strategy/create.rb
@@ -8,6 +8,7 @@ def association(runner)
8 8
       def result(attribute_assigner, to_create)
9 9
         attribute_assigner.object.tap do |result_instance|
10 10
           run_callbacks(:after_build, result_instance)
  11
+          run_callbacks(:before_create, result_instance)
11 12
           to_create[result_instance]
12 13
           run_callbacks(:after_create, result_instance)
13 14
         end
2  spec/factory_girl/strategy/create_spec.rb
@@ -2,7 +2,7 @@
2 2
 
3 3
 describe FactoryGirl::Strategy::Create do
4 4
   it_should_behave_like "strategy with association support", FactoryGirl::Strategy::Create
5  
-  it_should_behave_like "strategy with callbacks", :after_build, :after_create
  5
+  it_should_behave_like "strategy with callbacks", :after_build, :before_create, :after_create
6 6
 
7 7
   it "runs a custom create block" do
8 8
     block_run = false

0 notes on commit 24d417d

Please sign in to comment.
Something went wrong with that request. Please try again.