Module: NullDB

Defined in:
lib/nulldb/core.rb,
lib/nulldb_rspec.rb,
lib/nulldb/version.rb

Defined Under Namespace

Modules: RSpec Classes: Configuration

Constant Summary collapse

LEGACY_ACTIVERECORD =
Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('4.2.0')
VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.checkpointObject


38
39
40
# File 'lib/nulldb/core.rb', line 38

def checkpoint
  ActiveRecord::Base.connection.checkpoint!
end

.configurationObject


16
17
18
19
20
21
22
# File 'lib/nulldb/core.rb', line 16

def configuration
  if @configuration.nil?
    raise "NullDB not configured. Require a framework, ex 'nulldb/rails'"
  end

  @configuration
end

.configureObject


12
13
14
# File 'lib/nulldb/core.rb', line 12

def configure
  @configuration = Configuration.new.tap {|c| yield c}
end

.nullify(options = {}) ⇒ Object


24
25
26
27
28
29
30
# File 'lib/nulldb/core.rb', line 24

def nullify(options={})
  begin
    @prev_connection = ActiveRecord::Base.connection_pool.try(:spec)
  rescue ActiveRecord::ConnectionNotEstablished
  end
  ActiveRecord::Base.establish_connection(options.merge(:adapter => :nulldb))
end

.restoreObject


32
33
34
35
36
# File 'lib/nulldb/core.rb', line 32

def restore
  if @prev_connection
    ActiveRecord::Base.establish_connection(@prev_connection.config)
  end
end