gitlabhq/spec/factory.rb
Ariejan de Vroom b0ce61c4f2 Merge branch 'deploy_keys_nonunique' of https://github.com/miks/gitlabhq into miks-deploy_keys_nonunique
Added/fixed specs
Update spec/factory to allow Factory#new without opts

Conflicts:
	app/models/key.rb
2012-03-01 16:00:14 +01:00

30 lines
518 B
Ruby

class Factory
@factories = {}
class << self
def add(name, klass, &block)
@factories[name] = [klass, block]
end
def create(name, opts = {})
new(name, opts).tap(&:save!)
end
def new(name, opts = {})
factory= @factories[name]
factory[0].new.tap do |obj|
factory[1].call(obj)
end.tap do |obj|
opts.each do |k, opt|
obj.send("#{k}=", opt)
end
end
end
end
end
def Factory(name, opts={})
Factory.create name, opts
end