Older Rails Controller Tests
Understand how Rails 4 controller tests operated, including HTTP verb simulation, parameter handling, session and flash arguments, and Ajax call testing. Learn why features like render_template and assigns were deprecated in Rails 5 and how integration and unit testing approaches cover their functionality.
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 set ...