How to create data sandbox in rake tasks in Rails

Sometimes, we need data sandbox in take tasks such as load testing. When I was assigned to the development of load testing, I used this way.

ActiveRecord::Base.connection.begin_transaction  # sandbox data
User.create(name: 'John Doe')
ActiveRecord::Base.connection.rollback_transaction

In this case, a user is created, but the data is deleted after rollback_transaction.

My LinkedIn account is below! Please contact me!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

Tomoharu Tsutsumi
Tomoharu Tsutsumi

Written by Tomoharu Tsutsumi

5+ years Full Stack SWE (Ruby, Go, TypeScript, JavaScript) | Former Founding Engineer of AI Startup in Canada

No responses yet