Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

Commit

Permalink
Error was being raised when passing nil to create, fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zack Hobson committed Jun 4, 2009
1 parent 8e854f7 commit b2f2b8b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/modelfactory/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def next_counter
@counter += 1
end

def new_named(name, opt = {}, &block)
def new_named(name, opt, &block)
instance = @class.new
InstanceBuilder.new(instance, opt, next_counter, &@options[name])
instance
end

def create_named(name, opt = {}, &block)
def create_named(name, opt, &block)
instance = new_named(name, opt, &block)
instance.save!
instance.reload
Expand All @@ -52,7 +52,7 @@ def create_named(name, opt = {}, &block)
class InstanceBuilder # :nodoc:
def initialize(instance, params, counter, &block)
@instance = instance
@params = params
@params = params || {}
@counter = counter
@params.each { |attr, value| @instance.send "#{attr}=", value }
instance_eval(&block) if block_given?
Expand Down
4 changes: 4 additions & 0 deletions test/modelfactory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class ModelFactoryTest < Test::Unit::TestCase
assert_raises(ActiveRecord::RecordInvalid) { StrictWidget.factory.create }
end

should "not raise on nil params" do
assert_nothing_raised { Widget.factory.create(nil) }
end

context "with a specified default" do
setup do
ModelFactory.configure do
Expand Down

0 comments on commit b2f2b8b

Please sign in to comment.