I recently upgraded our Rails 4.1.7 codebase to the latest stable version of Rails 4.2.4. Since our codebase is quite large. We use lot of different gems. So the upgrade would definitely break lot of things. So I decide to do it step by step.
1. Upgrade to Rails 4.1.9
This step was quite easy for me. By changing the Rails version only in the Gemfile. And fix any dependencies conflict if any. And all specs was green for me. So all good, now ready for Rails 4.2.0
2. Upgrade to Rails 4.2.0
This is the important part. And I followed all the notes from here http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2. And yeah, it failed nearly of the unit tests (controllers/presenters/models/libs/..). In this step I only fix dependencies conflict. And got the bundle install done. I just ignored all those failed tests. I got a feeling that it might break again when I upgrade to 4.2.4. So I hold on the that until 4.2.4
3. Upgrade to Rails 4.2.4
Ok. So this is the final step. I planed to remove all the deprecated warnings. Of course after resolving all the dependencies conflicts. Updating all the gems which require >= Rails 4.2.x. Rails 4.2.4 actually changes many thing that not mentioned in the official documentation. Here’re couple of them:
- exists?(object) -> deprecated. Solution exists?(id)
- Arel::SqlLiteral.new -> undefined object. Solution Arel::Nodes::SqlLiteral.new
- belongs_to :objects, class: AnotherObject -> doesn’t exist class option anymore. Solution belongs_to :objects, class_name: ‘AnotherObject’
- where_values -> doesn’t work as expected like in the old version. This method not recommend to use. Solution: in my case I choose to use Arel instead to achieve the same result.
- deliver -> This method will be deprecated in Rails 5. However I resolve it anyway by using deliver_now or deliver_later
- And there’re many more small things come up. All I needed to do is solve them one by one. Until I got all the unit tests pass. In case you don’t have the unit tests. Then you pretty mess up.
Final words: Upgrading Rails 4.2.4 was not so difficult (in my case). Just require little of patient and debugging skill. The errors or breaks might different from each codebase. It depends on the gems you uses and the code also. So keep calm and upgrading Rails.
4. Couple of links that I found useful