RSpec.configure do |config|
INDEXED_MODELS = [BankAccount, Mandate, Transaction]
config.around(:each, search: true) do |example|
WebMock.disable_net_connect!(allow: ENV['ELASTICSEARCH_URL'] || 'localhost:9200')
INDEXED_MODELS.each { |klass| klass.__elasticsearch__.create_index! }
example.run
INDEXED_MODELS.each { |klass| klass.__elasticsearch__.delete_index! }
WebMock.disable_net_connect!
end
end
# spec/support/database_cleaner.rb
#
# Set sane default for database cleaner and add a meta tag to enable database commits.
# This is important if you need to test after_commit callbacks in rails. (i.e. elasticsearch)
#
require 'database_cleaner'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.around(:each) do |example|
DatabaseCleaner.strategy = example.metadata[:commit] ? :truncation : :transaction
DatabaseCleaner.cleaning do
example.run
end
end
end