Recently at work I had the opportunity to upgrade Rails from 4.2 all the way to Rails 6.1 for one of the core applications. With the experience, In this article I’m discussing some important points to consider when you are upgrading Rails.
Read the official guide
You would need to read Upgrading Ruby on Rails official guide to get you set. It goes through the steps to upgrade Rails one version at a time.
The official guide require you to have automated tests. This should include unit tests and end-to-end tests.
Unit tests will tests the code at a modular level and end-to-end tests cover the workflow of the application to ensure that the application still works as a whole. For example for end-to-end testing you may have a Cucumber+Selenium Web driver based setup.
Fix Deprecation Warnings
Rails can handle depraction warnings and report it back as you like. This is set by using
Go throught these deprecration warnings and fix them as some of the depration warnings can also be for the next Rails version.
You would have gem depedency issues in your Gemfile once you update Rails version. So you would need to update the Gems as you go. My advice is to use the lowest possible version of a Gem that supports the new Rails. This way you will have least possible changes coming from other Gems. Make sure to go through the Change logs of these Gem updates so that if something breaks in your tests, you will have more understand of the problem.
Configure Framework Defaults
As stated in the Rails upgrade guide, every new version since Rails 5, you will have a new file in the initializers for the new configuration defaults introduced in that version.
Once you have addressed that issues after updating Rails to the next version, you can look into this file and enable each default setting one at a time. Some of them improve security but also it would state if a specific configuration is not backward compatible.
This is where end-to-end testing is also crutial as sometimes unit tests might not detect issues as it would be related to the underlying architecture of the Web communication.