Add a controller test for the destroy
Task
- Add a controller test to check that the
LimericksController#destroy
method functions correctly for the happy path.
Steps
- Add Test:
- Controller test file:
test/controllers/limericks_controller_test.rb
- Test name:
"should destroy limerick"
- Arrange:
- Retrieve
User
fixture object one
.
- Sign in the user.
- Retrieve one of the user’s limericks (the first one in their collection).
- Act:
- Simulate an HTTP DELETE request.
- URL helper for HTTP request:
limerick_url
(with the retrieved limerick as an argument)
- Assert:
- Use
assert_difference
to check that the number of Limerick
objects in the database decreased by 1.
- Use
assert_response
to check that the HTTP response has a redirect status code.
- Use
assert_redirected_to
to check that the HTTP redirect was to the root URL.
- Use
assert_not_nil
to check that a flash['success']
message was set.
Reference Code and Commands
- Terminal command to run tests: