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

VERSION =
"1.1.1"

Class Method Summary collapse

Class Method Details

.checkpointObject



35
36
37
# File 'lib/nulldb/core.rb', line 35

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

.configurationObject



13
14
15
16
17
18
19
# File 'lib/nulldb/core.rb', line 13

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

  @configuration
end

.configureObject



9
10
11
# File 'lib/nulldb/core.rb', line 9

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

.nullify(options = {}) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/nulldb/core.rb', line 21

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



29
30
31
32
33
# File 'lib/nulldb/core.rb', line 29

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