Upgrading to Rails 5.0.0.beta1

December 21, 2015

What we did to upgrade a small Rails app from Rails 4.2.5 to Rails 5.0.0.beta1.

Now the upgrade is deployed in AWS, here is where we are at:

  1. When deploying, remember to change the secret key base to invalidate all sessions. ( or your users will get a nasty 500 error )
  2. Temporarily removed NewRelic from the gemfile – it doesn’t  currently support Rails 5.0.0.beta1. (UPDATE: as of 11 Feb NewRelic supports Rails 5.0.0.beta2)
  3. Temporarily removed rspec-rails from the gemfile to avoid a deployment error on AWS (ArgumentError while loading rspec-support.gemspec: couldn’t find HOME environment)

Steps to upgrade:

  1. We updated the rails gem version and ran bundle update, and upgraded gems including:

    gem ‘nokogiri’, ‘1.6.3.rc1’ upgraded to ‘1.6.8.rc1’
    gem 'newrelic_rpm' temporarily removed unltil support added for Rails 5.0
    gem 'aws-sdk', '1.66.0' upgraded to ‘2.2.7’
    gem 'coffee-rails', '4.0.1' upgraded to '4.1.1'
    gem 'coffee-script-source', '1.8.0' upgraded to '1.10.0'
    gem 'jquery-rails', '4.0.0.beta2' upgraded to '4.0.5'
    gem 'rspec-rails', '~> 3.1.0' upgraded to a git PR not yet released at the time:
    gem 'rspec-rails', :git => 'https://github.com/rspec/rspec-rails.git', :ref => '275905d'
    %w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
    gem lib, :git => "git://github.com/rspec/#{lib}.git", :branch => 'master'
  2. On running we got this compile error:

    /home/user/.rvm/gems/ruby-2.2-head@rails4.2.4/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:302:in `require': cannot load such file -- rack/commonlogger (LoadError)

    Solution: You have to use Puma for Rails 5.0 ( for Action Cable ). We were already using it but eventually tracked this down to the out-of-date puma gem version (2.9.1). To fix, specify the correct puma version in your gemfile:

    gem 'puma', '2.15.3'

    We also had to remove newrelic_rpm from the gem file because running bundle exec rake db:migrate caused this error:

    rake aborted!
    NameError: wrong constant name [[:error, ["detected unsupported rails version 5.0.0.beta1"], nil]]
    /home/rof/cache/bundler/ruby/2.2.0/gems/newrelic_rpm- `const_get'
  3. Add or update files required for this release:

    rake rails:update

    Additions / updates included :

    • config/application.rb
    • config/environments/development.rb, production.rb & test.rb ( carefully merge changes )
    • config/redis
    • config/initializers/active_record_belongs_to_required_by_default.rb
    • config/initializers/application_controller_renderer.rb
    • config/initializers/assets.rb
    • config/initializers/backtrace_silencers.rb
    • config/initializers/callback_terminator.rb
    • config/initializers/cors.rb
    • config/initializers/inflections.rb
    • bin/
  4. Test failures: we got 50% failures ( and 1000 DEPRECATION WARNINGs - probably many will be resolved when  rspec is updated. We will aim to get these down to zero again soon. )

    Of the 50% test failures:

    • 358  TypeErrors: can’t dump hash with default proc - all from one single line of code using Rails caching, easily fixed.
    • 93 are NoMethodError: assigns has been extracted to a gem. To continue using it, add gem ‘rails-controller-testing’ to your Gemfile.
    • 42 are NoMethodError: assert_template has been extracted to a gem. To continue using it, add gem ‘rails-controller-testing’ to your Gemfile.
    • 21 are NoMethodError: undefined method `normalize_params’ for Rack::Utils:Module
    • 1 is ActionView::Template::Error: nil is not a valid asset source

    To fix: the kaminari paginator causing an ArgumentError Generating an URL from non sanitized request parameters is insecure! - use the master branch from github:

    gem 'kaminari', :git => "git://github.com/amatsuda/kaminari.git", :branch => 'master'
  5. Deployment errors to AWS eb:

    There was a ArgumentError while loading rspec-support.gemspec:

    couldn't find HOME environment -- expanding `~' from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-b0ff0f6e1572/rspec-support.gemspec:22:in `expand_path' (Executor::NonZeroExitStatus)

    Temporary work-around : we run tests locally then comment-out rspec gems in gemfile before committing.

  6. Errors in production:

    a) On refreshing the browser with existing session - got a session crash with a marshal error. This is similar to https://github.com/rails/rails/issues/18164:

    TypeError (incompatible marshal file format (can't be read) format version 4.8 required; 123.34 given)

    To fix: change the secret key base to invalidate all sessions.

    b) Gmail started categorizing emails as spam.

    To fix: duplicate the environment ( to get a new IP address ), swap URLs and delete the old environment.

© 2018 Keith P | Follow on Twitter | Git