diff options
author | gitlabhq <m@gitlabhq.com> | 2011-10-09 00:36:38 +0300 |
---|---|---|
committer | gitlabhq <m@gitlabhq.com> | 2011-10-09 00:36:38 +0300 |
commit | 9ba1224867665844b117fa037e1465bb706b3685 (patch) | |
tree | 52fbfc1cdb55df21843965479c97be0c91121a9a /spec/factory.rb | |
parent | 93efff945215a4407afcaf0cba15ac601b56df0d (diff) | |
download | gitlab-ce-9ba1224867665844b117fa037e1465bb706b3685.tar.gz |
init commit
Diffstat (limited to 'spec/factory.rb')
-rw-r--r-- | spec/factory.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/factory.rb b/spec/factory.rb new file mode 100644 index 00000000000..29e552b1474 --- /dev/null +++ b/spec/factory.rb @@ -0,0 +1,29 @@ +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 + |