module Cucumber::Rails::Database

Constants

CUSTOM_STRATEGY_INTERFACE

Attributes

autorun_database_cleaner[RW]

Public Class Methods

after() click to toggle source
# File lib/cucumber/rails/database.rb, line 47
def after
  @strategy.after
end
before_js() click to toggle source
# File lib/cucumber/rails/database.rb, line 39
def before_js
  @strategy.before_js
end
before_non_js() click to toggle source
# File lib/cucumber/rails/database.rb, line 43
def before_non_js
  @strategy.before_non_js
end
default_strategy!() click to toggle source
# File lib/cucumber/rails/database.rb, line 34
def default_strategy!
  self.javascript_strategy = :truncation
  self.autorun_database_cleaner = true
end
javascript_strategy=(args) click to toggle source
# File lib/cucumber/rails/database.rb, line 19
def javascript_strategy=(args)
  strategy, *strategy_opts = args
  strategy_type =
    case strategy
    when Symbol
      map[strategy] || throw_invalid_strategy_error(strategy)
    when Class
      strategy
    end

  @strategy = strategy_type.new(*strategy_opts)

  validate_interface!
end

Private Class Methods

map() click to toggle source
# File lib/cucumber/rails/database.rb, line 53
def map
  {
    truncation: TruncationStrategy,
    shared_connection: SharedConnectionStrategy,
    transaction: SharedConnectionStrategy,
    deletion: DeletionStrategy,
    none: NullStrategy
  }
end
mapped_keys() click to toggle source
# File lib/cucumber/rails/database.rb, line 67
def mapped_keys
  map.keys.join(', ')
end
throw_invalid_strategy_error(strategy) click to toggle source
# File lib/cucumber/rails/database.rb, line 63
def throw_invalid_strategy_error(strategy)
  raise(InvalidStrategy, "The strategy '#{strategy}' is not understood. Please use one of #{mapped_keys}")
end
throw_invalid_strategy_interface_error() click to toggle source
# File lib/cucumber/rails/database.rb, line 77
def throw_invalid_strategy_interface_error
  raise(
    ArgumentError,
    "Strategy must respond to all of: #{CUSTOM_STRATEGY_INTERFACE.map { |method| "##{method}" } * '  '} !"
  )
end
validate_interface!() click to toggle source
# File lib/cucumber/rails/database.rb, line 71
def validate_interface!
  return if CUSTOM_STRATEGY_INTERFACE.all? { |m| @strategy.respond_to?(m) }

  throw_invalid_strategy_interface_error
end