Created
July 27, 2011 13:11
-
-
Save mgreenly/1109325 to your computer and use it in GitHub Desktop.
database cleaner multiple connections single orm outside of rails
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.before(:suite) do | |
ActiveRecord::Base.establish_connection database['one'] | |
DatabaseCleaner.strategy = :deletion | |
ActiveRecord::Base.establish_connection config.database['two'] | |
DatabaseCleaner.strategy = :deletion | |
end | |
config.before(:each) do | |
ActiveRecord::Base.establish_connection database['one'] | |
DatabaseCleaner.start | |
ActiveRecord::Base.establish_connection database['two'] | |
DatabaseCleaner.start | |
end | |
config.after(:each) do | |
ActiveRecord::Base.establish_connection database['one'] | |
DatabaseCleaner.clean | |
ActiveRecord::Base.establish_connection database['two'] | |
DatabaseCleaner.clean | |
end |
this does not work for me (version 1.5.0). I have to do the following
DatabaseCleaner.add_cleaner :active_record, model: ActiveRecord::Base
DatabaseCleaner.add_cleaner :active_record, model: Notification
ActiveRecord::Base
is using the default database.yml
while Notification
is connecting to a different database
@mgreenly it works for me. Stack:
rails 5.2.1
database_cleaner 1.7.0
rspec 3.7.1
Thank you! 👍
@luongm Worked like a charm!!!
@luongm solution is what worked for me, as well:
rails 6.0.2.1
database_cleaner 1.8.3
rspec 3.9.0
Worth mentioning:
Calling `DatabaseCleaner.add_cleaner` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.[]`, instead.
So, I did:
DatabaseCleaner.[] :active_record, model: ActiveRecord::Base
DatabaseCleaner.[] :active_record, model: SomeSpecificModel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ggalindezb Works for me!