Open kaorukobo opened 8 months ago
In the reproduction above, try replacing all the :db => :bar
with :db => Bar
. The test passes.
Looking into the database_cleaner/active_record/base.rb
, it is managing to obtain the ActiveRecord class from a given connection name.
It makes the code have too much responsibility and very complex. That is, it is reading ActiveRecord::Base.configurations
, reading config/database.yml
, and searching through connection pools and ActiveRecord classes.
This complexity can easily bring bugs such as #10, #18 and #97.
Though it is a breaking change... if we make the cleaner only accept an ActiveRecord class object as a value for :db
option, doesn't database_cleaner/active_record/base.rb
become far simpler and reduce the possibility of bugs so much?
(I will post my suggestion next to this report.)
Summary
When we add another database to a cleaner by specifying a symbol (connection name) with the
:transaction
strategy, it does not open a transaction.Look at the reproduction below. Even though the cleaner is configured to clean
:db => :bar
with the transaction strategy, the transaction is not opened*.(*In fact, a transaction is opened on
ActiveRecord::Base.connection
instead.)Reproduction