Skip to content

Deprecate usage of assigns and render_template in our controller tests

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Description

Rails 5 removes assigns and assert_template from its core and we have to include rails-controller-testing gem to migrate to Rails 5 (gitlab-foss!5555 (closed)). The motivations provided in http://blog.bigbinary.com/2016/04/19/changes-to-test-controllers-in-rails-5.html are following: (copy-paste)

Reasons for removing assigns and assert_template

The idea behind the removal of these methods is that instance variables and which template is rendered in a controller action are internals of a controller, and controller tests should not care about them.

According to Rails team, controller tests should be more concerned about what is the result of that controller action like what cookies are set, or what HTTP code is set rather than testing of the internals of the controller. So, these methods are removed from the core.

Proposal

Deprecate assigns and render_template in our controller specs. Include a section in https://docs.gitlab.com/ce/development/testing.html that asks people not to use them in new tests.

Status as of %13.8

$ git grep assigns -- {,ee/}spec/controllers | wc -l
442
$ git grep render_template -- {,ee/}spec/controllers | wc -l
251

Links / references

http://blog.bigbinary.com/2016/04/19/changes-to-test-controllers-in-rails-5.html

/cc @stanhu @dzaporozhets

Edited by 🤖 GitLab Bot 🤖