Class: Temping

Inherits:
Object
  • Object
show all
Defined in:
lib/temping.rb

Defined Under Namespace

Classes: ModelFactory

Class Method Summary collapse

Class Method Details

.cleanupObject



25
26
27
# File 'lib/temping.rb', line 25

def cleanup
  @model_klasses.each(&:destroy_all)
end

.create(model_name, options = {}, &block) ⇒ Object



8
9
10
11
12
13
# File 'lib/temping.rb', line 8

def create(model_name, options = {}, &block)
  factory = ModelFactory.new(model_name.to_s.classify, options, &block)
  klass = factory.klass
  @model_klasses << klass
  klass
end

.teardownObject



15
16
17
18
19
20
21
22
23
# File 'lib/temping.rb', line 15

def teardown
  @model_klasses.each do |klass|
    if Object.const_defined?(klass.name)
      klass.connection.drop_table(klass.table_name)
      Object.send(:remove_const, klass.name)
    end
  end
  @model_klasses.clear
end