Permalink
Browse files

Make sure a block exists when creating, too

  • Loading branch information...
joshuaclayton committed Nov 23, 2011
1 parent 557cce6 commit 86f971b25f2ba0e4befe2d605f4e5322e942356a
Showing with 7 additions and 7 deletions.
  1. +4 −5 lib/factory_girl/proxy/create.rb
  2. +3 −2 spec/factory_girl/proxy/create_spec.rb
@@ -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
@@ -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

0 comments on commit 86f971b

Please sign in to comment.