Controller Testing: Integration Tests
Learn about integration testing in Rails and write tests for your links controller.
Integration testing
Integration testing is done to check how various parts of the application interact. For example, creating a new link involves interaction between your controller and your model, and after successful creation, the controller has to render a view. If you want to check whether this interaction is successful, you can write an integration test for it.
Pre-test configuration
Before you can start writing your test, you must make some configurations keeping in mind the structure of your application.
Specifically, you must keep the following points in mind:
-
Your
Link
model is associated with yourUser
model. Everylink
you create in your fixtures must have auser
attribute. -
All actions, other than
index
andshow
, require an active user session to be accessed. This means a user must be signed in to create or delete a link.
Since you cannot disable these features of your application, you must make some configurations to your test environment before you can run tests on the full range of actions in your Links
controller.
test/controllers/links_controller_test.rb
In links_controller_test.rb
you will make the following additions to setup
:
Get hands-on with 1400+ tech skills courses.