Class: DatabaseCleaner::Strategy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Strategy

Override this method if the strategy accepts options



6
7
8
9
10
11
# File 'lib/database_cleaner/strategy.rb', line 6

def initialize(options=nil)
  if options
    name = self.class.name.sub("DatabaseCleaner::","").sub("::"," ") # e.g. "ActiveRecord Transaction"
    raise ArgumentError, "No options are available for the #{name} strategy."
  end
end

Instance Attribute Details

#dbObject



13
14
15
# File 'lib/database_cleaner/strategy.rb', line 13

def db
  @db ||= :default
end

Instance Method Details

#cleanObject

Override this method with the actual cleaning procedure. Its the only mandatory method implementation.

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/database_cleaner/strategy.rb', line 23

def clean
  raise NotImplementedError
end

#cleaning(&block) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/database_cleaner/strategy.rb', line 27

def cleaning(&block)
  begin
    start
    yield
  ensure
    clean
  end
end

#startObject

Override this method to start a database transaction if the strategy uses them



19
20
# File 'lib/database_cleaner/strategy.rb', line 19

def start
end