I have an existing project using mongoid, database_cleaner and rspec. I try to add active_admin, using the active_admin patches available. ActiveAdmin assumes it is in an ActiveRecord project, most specifically via its dependence on the meta_search gem.
When I go to run my specs, they all fail with the following error:
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::ConnectionNotEstablished:
ActiveRecord::ConnectionNotEstablished
# ./spec/support/database_cleaner.rb:12:in `block (2 levels) in <top (required)>'
The gem versions of the related libraries are as follows:
The file that the tests are failing on, spec/support/database_cleaner.rb
:
require 'database_cleaner'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid"
end
config.before(:each) do
DatabaseCleaner.clean
end
end
[moved from question]
It appears that database_cleaner attempts to autodetect the ORMs available to it in its initialization method
This can be pre-empted by changing the spec/support/database_cleaner.rb
file like so:
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner[:mongoid].strategy = :truncation
end
end
Calling the []
method in configuration overrides the autodetect such that ActiveRecord is no longer added.
Another workaround would have been to re-add a config/database.yml
file with a sqlite3 configuration that the rest of the application ignored. Thankfully that isn't necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With