Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a before_create callback

Closes #323
  • Loading branch information...
commit 24d417d5754a82a796bc45f0bf765df844c8d206 1 parent 4e2a672
@joshuaclayton joshuaclayton authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.