Description
Hey guys, first thank you for this great project! :)
I encountered lately an issue like this, where the ActiveRecord
constant was loaded,
but on purpose not used on an app. The rails_helper.rb
was configured
not to use transactions, etc.
Unfortunately, the FixtureSupport
module was configured for ActiveRecord
and errored like this:
ActiveRecord::ConnectionNotEstablished:
No connection pool with 'primary' found.
I figured out that ActiveStorage had a dependency on ActiveRecord, which I do not use.
The app just makes use of the ActiveStorage service, without any database records.
So I had to unload the ActiveRecord
constant on my rails_helper.rb
like this:
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Remove the ActiveRecord constant, because it is autloaded by
# ActiveStorage and not needed for our application. The presence
# of the ActiveRecord constant causes rspec-rails to include
# extra fixture support (see: https://goo.gl/6Ed17Y), which
# results in:
#
# ActiveRecord::ConnectionNotEstablished:
# No connection pool with 'primary' found.
#
Object.send(:remove_const, :ActiveRecord)
It would be better to have a configuration switch on rspec-rails to turn off any
handling of ActiveRecord. The guessing based on the availability of the constant
results in false-positive cases like mine.
Something like that would be helpful (guessing by default, but configurable):
RSpec.configure do |config|
# Disable all ActiveRecord handling
config.use_active_record = false
end
I'm also willing to send in a PR, if this is proposal is accepted. :)