Closed jdarnok closed 3 years ago
As I commented earlier, I'm not sure this isn't just a bug with rspec: https://github.com/rails/rails/issues/41549#issuecomment-851527738
🤦 Wow, whoops I thought this was the rails tracker... sorry!
Do you mind providing a sample application that reproduces the failure?
My reproduction attempt did not succeed so far:
mkdir rails-multi-pool
cd rails-multi-pool
echo "source 'https://rubygems.org\ngem 'rails'"
rvm use --create 2.7.2@rails-multi-pool
bundle
bundle exec rails new . --no-rc --skip-javascript --skip-bootsnap --skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --skip-spring
echo "group :development, :test do\ngem 'rspec-rails'\nend" >> Gemfile
bundle
bundle exec rails generate rspec:install
config/database.yml
:
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
primary:
<<: *default
database: db/development.sqlite3
secondary:
<<: *default
database: db/development2.sqlite3
test:
primary:
<<: *default
database: db/test.sqlite3
secondary:
<<: *default
database: db/test2.sqlite3
bundle exec rails generate model user
bundle exec rails generate model item --database=secondary
bundle exec rails generate controller hello
bundle exec rails db:migrate RAILS_ENV=test
$ rspec
4 examples, 0 failures, 4 pending
$ rm spec/models/*
$ rspec
2 examples, 0 failures, 2 pending
I've removed the following line from config/database.yml
:
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
$ rspec
2 examples, 0 failures, 2 pending
Lets move discussion back to the Rails issue, I'm 95% confident this is a Rails loading issue.
Hey guys! just want to let you know about a bug I've encountered with multiple databases on Rails 6.1 I've found similar case when I explained what happened: https://github.com/rails/rails/issues/41549
Basically, when you have models that are fetched from different databases - you have to provide
model
spec - it can be empty, but it has to be there. I presume it's some loading feature of rspec, because settingconfig.eager_load = true
in test environment fixes thatWay to reproduce - Just have models that are depending on
connects_to database:
. Then, if you try to run specs, but you don't have any model specs (let's say you want to run a controller spec) - you will encounter error from the title. Only works when you run tests globally though - when you try to run a single file (which is not a model test), it will fail againgemfile.lock