-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DatabaseCleaner.clean sometimes fails with undefined method "database_type" #4
Comments
here is a pry from within where i fails
I am unsure what "default" is in this instance and here is what
|
Stumbled upon the same issue. And you gave me a hint:
Turns out that it happens when you don't establish a database connection. Once you issue a |
I'm having this problem too. It's repeatable for specific run orders with a
I'm using database_cleaner v1.6.1, which is currently the latest release. What's the best way to fix this? It seems like creating a connection unnecessarily is not ideal. |
I am getting this error randomly in rails 5.1 |
My quick and dirty solution was to use an ENV var:
And then in the specs that don't need the database:
Regards, |
Seeing the same issue in Codeship with version |
@benoror Can you reduce it down to a repo you can share that reproduces the problem? I'd be happy to get to the bottom of it. |
Hey @botandrose thanks for the reply. I will try to have something soon that can replicate the issue, but I noted if happens randomly. For now, not sure if this could help, but here's our only place where we run # https://github.com/thoughtbot/factory_bot_rails
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
config.before(:suite) do
begin
DatabaseCleaner[:active_record].strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.start
FactoryBot.lint
ensure
DatabaseCleaner.clean
end
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end |
In our case it seems that there was a race condition between starting transactions with I based on existing examples from DatabaseCleaner & FactoryBot, and split them to make them play well together, by surrounding the
*The spec/support/database_cleaner.rb RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end spec/support/factory_bot.rb RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
config.before(:suite) do
DatabaseCleaner.start
FactoryBot.lint
DatabaseCleaner.clean
end
end |
NVM, failed again inside the CI (Codeship), trying this workaround instead: darren987469/membership-system#19 (comment) |
I got this error randomly, too. And it only occurs in one specific test case. My setting: RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end |
@khiav223577 I see that you're using database_cleaner v1.7.0. Can you try with latest v1.8 release (and/or database_cleaner-sequel gem) and tell me if the issue still is occurring? |
@khiav223577 Looking at your backtrace more closely, you appear to be using the ActiveRecord adapter, not the Sequel adapter, so this is not the bug for you! :) Can you open an issue on https://github.com/DatabaseCleaner/database_cleaner-active_record instead? |
Thanks for your quick reply. I'll try the latest version of database_cleaner and submit another issue if the issue still exists. |
For some reason DatabaseCleaner.clean fails occasionally with this error:
I am using the Sequel gem and have rspec configured with
The tests that fail are not even using and database operations, they are just unit tests
The text was updated successfully, but these errors were encountered: