Search code examples
ruby-on-railsactiverecordrspecmongoidrspec-rails

ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base with mongoid


I have a Rails 4.2.8 app, ruby 2.4.4 with a Mongo database, using the mongoid ODB. I want to run tests against this application using rspec. The most basic test gives me this error: ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base

My research on this problem lead me to these conclusions, but I do not know how to solve the problem itself:

  • why is active record mentionned here, when it is not in my gemfile ? Maybe another gem is loading it at some point, but how can i get rid of this problem ?
  • my application.yml and mongoid.yml file are correctly configured. I can RAILS_ENV=TEST rails console and I can query documents.
  • looks like rails is going inside the condition line 15 in this file. So how and why is ActiveRecord loaded at some point ?

Some help would really be appreciated as I do not know what to do next...


Solution

  • Ok so I did not figure out who was loading ActiveRecord in my application, but I manually unload it in my rails_helper.rb:

    Object.send(:remove_const, :ActiveRecord)
    # Make sure it is above this
    require 'rspec/rails'