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:
- activeadmin (0.4.2)
- database_cleaner (0.7.1)
- mongoid (2.4.5)
- meta_search (1.1.3)
- activerecord (3.2.1)
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.rbfile like so: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.ymlfile with a sqlite3 configuration that the rest of the application ignored. Thankfully that isn’t necessary.