Last active
August 29, 2015 14:04
-
-
Save namxam/4ed441517782d774af26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment