class DatabaseCleaner::Strategy

Attributes

db[W]

Public Class Methods

new(options=nil) click to toggle source

Override this method if the strategy accepts options

# 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

Public Instance Methods

clean() click to toggle source

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

# File lib/database_cleaner/strategy.rb, line 23
def clean
  raise NotImplementedError
end
cleaning() { || ... } click to toggle source
# File lib/database_cleaner/strategy.rb, line 27
def cleaning(&block)
  begin
    start
    yield
  ensure
    clean
  end
end
db() click to toggle source
# File lib/database_cleaner/strategy.rb, line 13
def db
  @db ||= :default
end
start() click to toggle source

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

# File lib/database_cleaner/strategy.rb, line 19
def start
end