Module: FactoryGirl::Preload
- Defined in:
- lib/factory_girl/preload.rb,
lib/factory_girl/preload/engine.rb,
lib/factory_girl/preload/helpers.rb,
lib/factory_girl/preload/version.rb
Defined Under Namespace
Modules: Helpers, Version Classes: Engine
Class Attribute Summary collapse
-
.clean_with ⇒ Object
Returns the value of attribute clean_with.
-
.factories ⇒ Object
Returns the value of attribute factories.
-
.preloaders ⇒ Object
Returns the value of attribute preloaders.
-
.record_ids ⇒ Object
Returns the value of attribute record_ids.
Class Method Summary collapse
- .active_record ⇒ Object
- .clean(*names) ⇒ Object
- .connection ⇒ Object
- .reload_factories ⇒ Object
- .run ⇒ Object
Class Attribute Details
.clean_with ⇒ Object
Returns the value of attribute clean_with.
20 21 22 |
# File 'lib/factory_girl/preload.rb', line 20 def clean_with @clean_with end |
.factories ⇒ Object
Returns the value of attribute factories.
18 19 20 |
# File 'lib/factory_girl/preload.rb', line 18 def factories @factories end |
.preloaders ⇒ Object
Returns the value of attribute preloaders.
17 18 19 |
# File 'lib/factory_girl/preload.rb', line 17 def preloaders @preloaders end |
.record_ids ⇒ Object
Returns the value of attribute record_ids.
19 20 21 |
# File 'lib/factory_girl/preload.rb', line 19 def record_ids @record_ids end |
Class Method Details
.active_record ⇒ Object
28 29 30 |
# File 'lib/factory_girl/preload.rb', line 28 def self.active_record ActiveRecord::Base end |
.clean(*names) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/factory_girl/preload.rb', line 46 def self.clean(*names) query = case clean_with when :truncation then try_truncation_query when :deletion then "DELETE FROM %s" else raise "Couldn't find #{clean_with} clean type" end names = active_record.descendants.collect(&:table_name).uniq if names.empty? connection.disable_referential_integrity do names.each do |table| connection.execute(query % connection.quote_table_name(table)) end end end |
.connection ⇒ Object
32 33 34 |
# File 'lib/factory_girl/preload.rb', line 32 def self.connection active_record.connection end |
.reload_factories ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/factory_girl/preload.rb', line 62 def self.reload_factories factories.each do |class_name, group| group.each do |name, factory| factories[class_name][name] = nil end end end |
.run ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/factory_girl/preload.rb', line 36 def self.run helper = Object.new.extend(Helpers) connection.transaction :requires_new => true do preloaders.each do |block| helper.instance_eval(&block) end end end |