Method: Webhookdb::SpecHelpers::Postgres.included

Defined in:
lib/webhookdb/spec_helpers/postgres.rb

.included(context) ⇒ Object

Inclusion callback – install some hooks



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 30

def self.included(context)
  context.around(:each) do |example|
    Webhookdb::Postgres.unsafe_skip_transaction_check = true if example.[:no_transaction_check]

    _truncate(example)
    setting = example.[:db]
    if setting && setting != :no_transaction
      Webhookdb::SpecHelpers::Postgres.wrap_example_in_transactions(example)
    else
      Webhookdb::Postgres.logger.debug "Running spec without a transaction"
      example.run
    end
  end

  context.after(:each) do |example|
    Webhookdb::Postgres.unsafe_skip_transaction_check = false if example.[:no_transaction_check]

    truncate_all if example.[:db] == :no_transaction
    _truncate(example)
  end

  super
end