More Roles Tests

Let's learn how to write tests for users and roles.

We'll cover the following

Adding more roles test

In the previous lesson, we created a custom matcher, be_able_to_see, which takes in a list of projects and validates the can_view? and visible_projects in parallel, thereby asserting that the two methods stay in sync. It also validates that projects that aren’t specified are not visible. We get around the fixture data by explicitly specifying the universe of all_projects. (In Minitest we’d use a custom assertion. We can see an example in the sample code at /test/models/user_test.rb).

At this point, our original integration test is still failing because we haven’t integrated the controller with the new model function. The controller method still calls Project.all, but we can fix that:

Get hands-on with 1400+ tech skills courses.