Loading fixtures data
Rails comes with database fixture commands under db:fixtures
namespace and the one we need to check for loading the fixtures without issues is load
:
bin/rails db:fixtures:load RAILS_ENV=test
This command will try to load all fixtures into your test database. If there are YAML errors, missing references, or foreign key violations, it will fail right away. If we run this later in development, we get to work with our fixtures state in the application instead of trying to manually add some data.
There is no problem in loading fixtures again and again since that's what's happening with every single test anyways.
But why?
The reason to run this command before running any tests is that you'll know your tests aren't just failing because you introduced a slight error in your fixtures. It's very useful after refactoring lots of fixtures at once.