Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sathiyaseelan/27a5410e28a3f2ebcf4855621aff32bb to your computer and use it in GitHub Desktop.
Save sathiyaseelan/27a5410e28a3f2ebcf4855621aff32bb to your computer and use it in GitHub Desktop.
Database cleaner configuration for apps using both mongoid and activerecord
# Database cleaner configuration for apps using both mongoid and activerecord.
When your apps using multiple ORMs, you might want to fine tune each ORM in different way.
This contains the sample configuration for using mongoid and activerecord together.
This shows how to use different startegy for different ORMs.
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner[:mongoid].clean_with(:truncation)
DatabaseCleaner[:active_record].clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner[:active_record].strategy = :transaction
DatabaseCleaner[:mongoid].strategy = :truncation
end
config.before(:each, js: true) do
DatabaseCleaner[:active_record].strategy = :truncation
DatabaseCleaner[:mongoid].strategy = :truncation
end
config.before(:each) do
DatabaseCleaner[:activerecord].start
DatabaseCleaner[:mongoid].start
end
config.after(:each) do
DatabaseCleaner[:activerecord].clean
DatabaseCleaner[:mongoid].clean
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment