Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RailsConf 2019: Upgrade Rails 101 Workshop

RailsConf 2019: Upgrade Rails 101 Workshop

This is a presentation about upgrading Rails applications following a process that has worked very well at fastruby.io

After following the steps in this presentation you will have the roadmap to get to the next version of Rails.

You can find the companion page to this workshop over here: https://fastruby.io/upgrade

Ernesto Tagwerker

May 02, 2019
Tweet

More Decks by Ernesto Tagwerker

Other Decks in Programming

Transcript

  1. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade Exercise #1: Check Pre-Requisites Time:

    10 minutes https://fastruby.io/upgrade#1 https://fastruby.io/upgrade#2 https://fastruby.io/upgrade#3
  2. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 35 Exercise #2: Check Test

    Coverage Time: 15 minutes https://fastruby.io/upgrade#4
  3. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade ... ✅ 2.3 3.0 ✅

    3.0 3.1 ✅ 3.1 3.2 ✅ 3.2 4.0 ✅ 4.0 4.1 ✅ 4.1 4.2 ✅ 4.2 5.0 ✅ 5.0 5.1 ✅ 5.1 5.2 ✅ 5.2 6.0 41 Gemfile Gemfile.next { }
  4. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 62 $ bundle outdated Fetching

    gem metadata from https://rubygems.org/. Resolving dependencies..... Outdated gems included in the bundle: * actioncable (newest 5.2.3, installed 5.1.6) * actionmailer (newest 5.2.3, installed 5.1.6) * actionpack (newest 5.2.3, installed 5.1.6) * actionview (newest 5.2.3, installed 5.1.6) ...
  5. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade Does your build pass? -

    Submit a PR - Create a story 66 … and move on to the next fixed dependency
  6. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 69 Exercise #3: Relax your

    Gemfile Time: 10 minutes https://fastruby.io/upgrade#5
  7. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 74 # Gemfile group :development

    do gem "ten_years_rails", git: "https://github.com/fastruby/ten_years_rails_conf_2018.git", branch: "fixes/ruby-2-2-syntax-error" end
  8. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 76 $ bundle_report outdated cucumber-rails

    1.4.0: released over 5 years ago (latest version, 1.7.0, released 11 days ago) rack-test 0.6.3: released over 4 years ago (latest version, 1.1.0, released 9 months ago) cucumber-wire 0.0.1: released over 3 years ago (latest version, 1.0.0, released 7 months ago) cucumber-core 1.5.0: released almost 3 years ago (latest version, 4.0.0, released 7 months ago) cucumber 2.4.0: released almost 3 years ago (latest version, 3.1.2, released 10 months ago) arel 6.0.4: released over 2 years ago (latest version, 9.0.0, released over 1 year ago) ... ... ... 35 of the 143 gems are out-of-date (24%)
  9. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 77 $ bundle_report compatibility --rails-version=6.0.0.rc1

    => Incompatible with Rails 6.0.0.rc1 (with new versions that ar compatible): These gems will need to be upgraded before upgrading to Rails 6.0.0.rc1. rails-controller-testing 1.0.2 - upgrade to 1.0.4 responders 2.4.0 - upgrade to 2.4.1 2 gems incompatible with Rails 6.0.0.rc1 (this is for an app running Rails 5.1.4)
  10. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 78 $ next --init Created

    Gemfile.next (a symlink to your Gemfile). Your Gemfile has been modified to support dual-booting! There's just one more step: modify your Gemfile to use a newer version of Rails using the `next?` helper method. For example, here's how to go from 5.2.3 to 6.0: if next? gem "rails", "6.0.0" else gem "rails", "5.2.3" end
  11. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 79 # Gemfile def next?

    File.basename(__FILE__) == "Gemfile.next" end source 'https://rubygems.org' gem 'rails', '~> 5.1.4’
  12. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 80 # Gemfile if next?

    gem 'rails', '~> 5.2.3' else gem 'rails', '~> 5.1.4' end
  13. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 84 $ BUNDLE_GEMFILE=Gemfile.next \ bundle

    install Bundler could not find compatible versions for gem "activesupport": In snapshot (Gemfile.lock): activesupport (= 4.2.1) In Gemfile: activeadmin was resolved to 1.0.0.pre4, which depends on arbre (>= 1.0.2, ~> 1.0) was resolved to 1.1.1, which depends on activesupport (>= 3.0.0) activeadmin was resolved to 1.0.0.pre4, which depends on inherited_resources (~> 1.6) was resolved to 1.7.0, which depends on .
  14. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 95 $ BUNDLE_GEMFILE=Gemfile.next \ bundle

    exec rake rake aborted! Bundler::GemRequireError: There was an error while trying to load the gem 'test_after_commit'. Gem Load Error is: after_commit testing is baked into rails 5, you no longer need test_after_commit gem Backtrace for gem load error is: /Users/etagwerker/.rvm/gems/ruby-2.4.5@petitions/gems/ test_after_commit-1.1.0/lib/test_after_commit.rb:4:in `<top (required)>' /Users/etagwerker/.rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/ bundler/runtime.rb:81:in `require' /Users/etagwerker/.rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/ bundler/runtime.rb:81:in `block (2 levels) in require' /Users/etagwerker/.rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/ bundler/runtime.rb:76:in `each'
  15. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 96 # Gemfile group :test

    do gem 'nokogiri' gem 'shoulda-matchers' gem ‘pickle' unless next? gem ‘test_after_commit' end end
  16. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 97 $ BUNDLE_GEMFILE=Gemfile.next \ bundle

    exec rake NoMethodError: undefined method `hide_action' for Delayed::Web::ApplicationController:Class # ./config/initializers/delayed_web.rb:10:in `block in <top (required)>' # ./config/initializers/delayed_web.rb:7:in `class_eval' # ./config/initializers/delayed_web.rb:7:in `<top (required)>' # /Users/etagwerker/.rvm/gems/ruby-2.4.5@petitions/gems/ activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `load' # /Users/etagwerker/.rvm/gems/ruby-2.4.5@petitions/gems/ activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `block in load' # /Users/etagwerker/.rvm/gems/ruby-2.4.5@petitions/gems/ activesupport-5.0.7.2/lib/active_support/dependencies.rb:259:in `load_dependency'
  17. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 98 # config/initializers/delayed_web.rb Delayed::Web::ApplicationController.class_eval do

    include Authentication, FlashI18n hide_action :admin_request? def admin_request? true end protected def admin_login_url main_app.admin_login_url end end
  18. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 99 # config/initializers/delayed_web.rb Delayed::Web::ApplicationController.class_eval do

    include Authentication, FlashI18n protected def admin_request? true end def admin_login_url main_app.admin_login_url end end
  19. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 101 $ BUNDLE_GEMFILE=Gemfile.next bundle exec

    rake DEPRECATION WARNING: The success? predicate is deprecated and will be removed in Rails 6.0. Please use successful? as provided by Rack::Response::Helpers. (called from block (3 levels) in <top (required)> at /Users/etagwerker/Projects/ ombulabs/fastruby.io/spec/controllers/ contacts_controller_spec.rb:20) .DEPRECATION WARNING: The success? predicate is deprecated and will be removed in Rails 6.0. Please use successful? as provided by Rack::Response::Helpers. (called from block (4 levels) in <top (required)> at /Users/etagwerker/Projects/ ombulabs/fastruby.io/spec/controllers/ contacts_controller_spec.rb:32) ..DEPRECATION WARNING: The success? predicate is deprecated and will be removed in Rails 6.0. Please use successful? as provided by Rack::Response::Helpers. (called from block (4 levels) in <top (required)> at /Users/etagwerker/Projects/ ombulabs/fastruby.io/spec/controllers/ contacts_controller_spec.rb:52) ..........
  20. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade Unofficial Guides 104 1.https://fastruby.io/blog/rails/upgrades/upgrade-to-rails-3.html 2.https://fastruby.io/blog/rails/upgrades/upgrade-to-rails-3-1.html

    3.https://fastruby.io/blog/rails/upgrades/upgrade-to-rails-3-2.html 4.https://fastruby.io/blog/rails/upgrades/upgrade-rails-from-3-2-to-4-0.html 5.https://fastruby.io/blog/rails/upgrades/upgrade-rails-from-4-0-to-4-1.html 6.https://fastruby.io/blog/rails/upgrades/upgrade-rails-from-4-1-to-4-2.html 7.https://fastruby.io/blog/rails/upgrades/active-record-5-1-api-changes.html 8.https://fastruby.io/blog/rails/upgrades/upgrade-rails-from-4-2-to-5-0.html 9.https://fastruby.io/blog/rails/upgrades/upgrade-rails-from-5-0-to-5-1.html 10.https://fastruby.io/blog/rails/upgrades/upgrade-rails-from-5-1-to-5-2.html 11.https://fastruby.io/blog/rails/upgrades/upgrade-rails-from-5-2-to-6-0.html
  21. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 107 Exercise #5: next bundle

    exec rake Time: 15 minutes https://fastruby.io/upgrade#7
  22. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade # config/environments/test.rb Rails.application.configure do #

    ... # Raise on deprecation notices config.active_support.deprecation = :raise # ... end 111
  23. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade # Rakefile # ... task

    default: %i[ bundle:audit brakeman:check spec spec:javascripts cucumber ] 113
  24. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade namespace :bundle do desc "Audit

    bundle for any known vulnerabilities" task :audit do unless system "bundle-audit check --update" exit 1 end end end 114
  25. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 116 # Gemfile source 'https://rubygems.org'

    git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" end if next? gem 'rails', github: 'rails/rails' else gem 'rails', '~> 6.0.0.rc1' end
  26. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade 117 Exercise #6: Set Up

    to Stay Current Time: 5 minutes https://fastruby.io/upgrade#8
  27. @etagwerker | #RailsUpgrades | https://fastruby.io/upgrade Resources 120 1.https://github.com/clio/ten_years_rails 2.https://github.com/alphagov/e-petitions 3.https://github.com/rubyperu/ready4rails

    4.https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#the-upgrade-process 5.https://fastruby.io/blog/tags/upgrades 6.https://semver.org 7.https://github.com/Shopify/bootboot 8.https://github.com/fastruby/rails_upgrader 9.http://railsdiff.org 10.https://github.com/hintmedia/moderate_parameters 11.https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#the-update-task