You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: I will make a pull request that follows this issue.
Summary
When we use DatabaseCleaner for a multi-database environment, the connection for "main" models (i.e., models inheriting the connection pool from ActiveRecord::Base) gets replaced with the connection for non-main models.
setcwd_to_tmpdirload_gemscreate_config_database_ymlsetup_activerecord# defines Foo model, which use the connection pool from ApplicationRecord.defdefine_foo_modeleval(<<~RUBY,TOPLEVEL_BINDING) class Foo < ApplicationRecord connection.exec_query "CREATE TABLE foos (id INTEGER PRIMARY KEY)" reset_column_information end RUBYend# defines Bar model, which connects to alternate DB to be cleaned by DatabaseCleaner.defdefine_bar_modeleval(<<~RUBY,TOPLEVEL_BINDING) class Bar < ApplicationRecord establish_connection :bar connection.exec_query "CREATE TABLE bars (id INTEGER PRIMARY KEY)" reset_column_information end RUBYendRSpec.describedoit"works"dodefine_foo_modelexpect(Foo.connection.tables).toeq(["foos"])cleaner=DatabaseCleaner::Cleaners.newcleaner[:active_record,:db=>:bar].strategy=:truncationcleaner.clean# define Bar model after `cleaner.clean`define_bar_model# Foo.connection gets replaced with Bar's connection!## expected: ["foos"]# got: ["bars"]expect(Foo.connection.tables).toeq(["foos"])endend
The text was updated successfully, but these errors were encountered:
Note: I will make a pull request that follows this issue.
Summary
When we use DatabaseCleaner for a multi-database environment, the connection for "main" models (i.e., models inheriting the connection pool from ActiveRecord::Base) gets replaced with the connection for non-main models.
Reproduction
For the full reproduction code, see https://gist.github.com/kaorukobo/8dd0e5ef6c8662cc5de88aceea5043a1
The text was updated successfully, but these errors were encountered: