Skip to content

Commit

Permalink
Add a before_create callback
Browse files Browse the repository at this point in the history
Closes #323
  • Loading branch information
joshuaclayton committed Mar 30, 2012
1 parent 4e2a672 commit 24d417d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/factory_girl.rb
Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/factory_girl/strategy/create.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/strategy/create_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 24d417d

Please sign in to comment.