Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
database cleaner configuration
# spec_helper.rb
RSpec.configure do |config|
# earlier configurations omitted ...
# Set config.use_transactional_fixtures to false
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
#########################
# spec/support/shared_db_connection.rb
classActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.