Search⌘ K

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.

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.

Ruby
one:
title: MyString
price: 9.99
published: false
user: one
two:
title: MyString
price: 9.99
published: false
user: two

Note that this fixture does not use the attribute user_id, but rather user. This means ...