Rails 6.0 + Rspec + Multiple Databases + Using Transactions vs Truncation

69 views
Skip to first unread message

Sean Smith

unread,
Jun 23, 2020, 12:42:25 PM6/23/20
to rspec
I'm using Rails 6.0 for API purposes only, we have a 3 DB setup with multiple databases typically being accessed during a single request spec. We've issues using transactions to clean the database with multiple databases. I've tried setting up something similar to this: http://joshfrankel.me/blog/configure-rspec-for-multiple-databases-with-database-cleaner-support/ and tried every variation I could think of, but still have problems. Is there any guide for setting up rspec + Rails 6.0 + multiple databases? I was able to get a working solution using DatabaseCleaner + truncation as a strategy but as our suite has grown I'd love to get back the performance benefit of transactions. I played around more last night and still had similar issues. I can describe what seems to be happening in more detail if needed, but as of yet I haven't found any good resources on the best way to achieve this setup.

Jon Rowe

unread,
Jun 24, 2020, 7:06:02 AM6/24/20
to rs...@googlegroups.com
Hi Sean

I can’t offer any specific advise because it’s been a while since I had to do this, but I can say that rspec shouldn’t be the factor blocking you here, rspec-rails is a thin wrapper over rails own test helpers, so any generic rails / multiple database guide should offer help.

I had a look at the article and it looks to me (as the RSpec maintainer and a former DatabaseCleaner contributor) like it should work, if you want to provide more details maybe people can offer more specific feedback?

If it turns out there is something you can’t access from Rails 6 within RSpec I’m keen to help there.

Cheers
Jon Rowe
---------------------------
Reply all
Reply to author
Forward
0 new messages