Open clemens opened 7 years ago
i have the same issue in jruby 9.1.12.0-p0: database_cleaner (1.6.1) rspec-core (3.6.0) activerecord (4.2.0) activerecord-jdbc-adapter (1.3.23) activerecord-oracle_enhanced-adapter (1.6.9)
@clemens Hi, just curious, why are these lines commented out?
# primary_cleaner.start
# primary_cleaner.clean
During my testing, I cared about the tenant database, not the primary one. In my actual test suite, obviously both should be cleaned.
I've used DatabaseCleaner for several years (thanks!) without issues. But my current setup seems to not work properly.
Basic setup:
On noteworthy thing about the app here is that it's using multiple databases: One main database and several tenant databases. In the test environment, this currently means two databases in total (main + test tenant).
Here's the test setup:
Now when I have 2 examples in RSpec which both use the same basic setup with a test patient (
Patient.create!(email: 'john@doe.com', ...)
), the uniqueness constraint on email fails because apparently the record exists already. The debugging code in the output (from theputs
statements above) confirms this:(I've numbered some lines to make it easier to follow. The
[DatabaseCleaner]
output comes from someputs
statements I've put in the corresponding strategy in https://github.com/DatabaseCleaner/database_cleaner/blob/master/lib/database_cleaner/active_record/transaction.rb.)(1) Before the first example (in the first
before
block), there are 0 patients in the tenant database => expected. (2)tenant_cleaner.start
has caused an open transaction in the tenant database => expected. (3) Running the example has created a patient in the tenant database => expected. (4)tenant_cleaner.clean
rolls back the transaction => expected. (5) There is still 1 patient in the tenant database => this is NOT expected. (6) Thebefore
block of the next example confirms that 1 patient has remained in the tenant database => this is NOT expected.Commenting in/out the cleaning of the primary database doesn't change anything (I wouldn't have expected it to either, but I tried it nonetheless).
Does anyone have any insights as to what's going wrong here?
Thanks a lot in advance.