Sha256: 0e67eb79057a4b011c773c939d3ae2fd01d15c6d8a8d8136d56dcad82c2a20f6
Contents?: true
Size: 1.18 KB
Versions: 3
Compression:
Stored size: 1.18 KB
Contents
module Factory module Preload autoload :Helpers, "factory_girl/preload/helpers" autoload :Version, "factory_girl/preload/version" require "factory_girl/preload/rspec2" if defined?(RSpec) require "factory_girl/preload/extension" class << self attr_accessor :preloaders attr_accessor :factories end self.preloaders = [] self.factories = {} def self.run helper = Object.new.extend(Helpers) ActiveRecord::Base.connection.transaction :requires_new => true do preloaders.each do |block| helper.instance_eval(&block) end end end def self.clean(*names) query = ActiveRecord::Base.connection.class.name == "ActiveRecord::ConnectionAdapters::SQLite3Adapter" ? "DELETE FROM `%s`" : "TRUNCATE TABLE `%s`" names = ActiveRecord::Base.descendants.collect(&:table_name).uniq if names.empty? names.each {|table| ActiveRecord::Base.connection.execute(query % table)} end def self.reload_factories factories.each do |class_name, group| group.each do |name, factory| factories[class_name][name] = factory.class.find(factory.id) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
factory_girl-preload-1.0.1 | lib/factory_girl/preload.rb |
factory_girl-preload-1.0.0 | lib/factory_girl/preload.rb |
factory_girl-preload-1.0.0.rc1 | lib/factory_girl/preload.rb |