Skip to content

Commit

Permalink
Make sure a block exists when creating, too
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Nov 23, 2011
1 parent 557cce6 commit 86f971b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 4 additions & 5 deletions lib/factory_girl/proxy/create.rb
Expand Up @@ -3,11 +3,10 @@ class Proxy #:nodoc:
class Create < Build #:nodoc:
def result(to_create)
super
if to_create
to_create.call(@instance)
else
@instance.save!
end

to_create ||= lambda {|instance| instance.save! }
to_create[@instance]

run_callbacks(:after_create)
@instance
end
Expand Down
5 changes: 3 additions & 2 deletions spec/factory_girl/proxy/create_spec.rb
Expand Up @@ -17,10 +17,11 @@
end

it "runs a custom create block" do
block = stub('custom create block', :call => nil)
block_run = false
block = lambda { block_run = true }
subject.result(block)
block.should have_received(:call).with(instance)
instance.should have_received(:save!).never
block_run.should be_true
end

end
Expand Down

0 comments on commit 86f971b

Please sign in to comment.