...

/

Older Rails Controller Tests

Older Rails Controller Tests

Learn about controller tests and controller tests methods provided by Rails older versions.

In Rails 5, two features of controller testing, one commonly used, one less so, were deprecated. This deprecation has the effect of limiting the scope of controller testing. In the eyes of the Rails core, this scope should be picked up by integration testing, though we’d suggest that some of it should be picked up by moving code out of the controller and unit-testing it. The following is a quick guide to what Rails 4 controller tests looked like, as we’ll probably see a bunch of them.

Controller test requests

Rails 4 provided the same set of methods we’ve covered for creating a request: get, post and their friends. However, the method parameters were different:

get :show, {id: @task.id}, {user_id: "3",
    current_project: @project.id.to_s}, {notice: "flash test"}

The get method

Here, the method name, get, is the HTTP verb being simulated, sort of. While the controller test will ...