Unit Tests
Explore how to create and run unit tests for the User and Product models in a Rails API. Understand validation testing and how to ensure cascading deletions work properly when users are removed.
We'll cover the following...
We'll cover the following...
Data for testing
As discussed earlier, we need a user with one of the products to test the Product model and its interaction with the User model. Take a look at the fixture.yml of the Product model below.
Note that this fixture does not use the attribute user_id, but rather user. This means ...