testdouble/cypress-rails

Prepopulate database with FactoryBot

Closed this issue · 1 comments

Hey this project is awesome. How can I prepopulate database with FactoryBot?

You can really do just about anything you like with setting up custom Ruby state or test data. If you're using the transactional server (the default), as mentioned in the README, you can populate the database in either the before_server_start or after_transaction_start hooks. Then be sure to send an HTTP request to /cypress_rails_reset_state and it will clear the DB state.

If you have test-specific state to setup, you can create your own route/controller that only runs in RAILS_ENV=test that you can call to set up specific data scenarios and send requests to it after resetting state so that the database gets populated with whatever your test needs