Created
November 24, 2017 10:49
-
-
Save sathiyaseelan/27a5410e28a3f2ebcf4855621aff32bb to your computer and use it in GitHub Desktop.
Database cleaner configuration for apps using both mongoid and activerecord
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
# 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. |
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| | |
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