Slide 1

Slide 1 text

@nathany Upgrading Rails

Slide 2

Slide 2 text

Rails 1.2 Rails 2.x Rails 3.x

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

porting to Rails 4 • Sometimes the new code still works in Rails 3:
 
 scope :sorted, order(“updated_at")
 
 scope :sorted, -> { order("updated_at") } • What if it doesn’t? Branch?

Slide 5

Slide 5 text

dual-boot # Gemfile ! module ::Kernel
 def rails4?
 ENV["RAILS4"]
 end
 end
 if rails4?
 # monkey patch Bundler to support multiple lock files…
 # https://github.com/discourse/discourse/blob/master/Gemfile
 end RAILS4=1 rails s

Slide 6

Slide 6 text

rails4? # Gemfile
 
 if rails4?
 gem "rails", “4.0.5" # protected_attributes, etc.
 else
 gem "rails", "3.2.18"
 end 
 # config/environments/test.rb
 
 ActiveSupport::Deprecation.silenced = true if rails4?


Slide 7

Slide 7 text

RailsDiff

Slide 8

Slide 8 text

incremental progress • Boot Server • Run Tests (Rails 3 & 4) • Passing Tests • QA • Switch Default Rails

Slide 9

Slide 9 text

whoops • Non-digest images in emails, use public/ • Blocks iframe embedding
 response.headers.except! ‘X-Frame-Options' • Endpoints
 protect_from_forgery exceptions (CSRF)
 xml_data = Hash.from_xml(request.body.read) • Threading bug in activerecord-session_store

Slide 10

Slide 10 text

if rails_master?
 # gem "rails", :github => "rails/rails", :branch => "4-1-stable"
 gem "rails", "4.1.2.rc2"
 else
 gem "rails", "4.0.5"
 end

Slide 11

Slide 11 text

bonus round Rails 2.x zero tests

Slide 12

Slide 12 text

porting to Rails 3 • Prerequisite: Bundler
 http://bundler.io/v1.6/rails23.html • Boot server and run tests in an evening.
 Still a long ways to go.

Slide 13

Slide 13 text

Gemfile # Gemfile
 module ::Kernel
 def rails3?
 ENV["RAILS3"]
 end
 end ! if rails3?
 gem 'rails', '3.0.20'
 gem 'prototype_legacy_helper', '0.0.0', :github => 'rails/ prototype_legacy_helper'
 else
 gem 'rails', ‘2.3.18' gem 'fake_arel'
 end

Slide 14

Slide 14 text

booting # environment.rb
 
 if rails3?
 require File.expand_path('../environment3', __FILE__)
 else
 require File.expand_path('../environment2', __FILE__)
 end
 # boot.rb ! if rails3?
 puts "Booting Rails 3..."
 require File.expand_path('../boot3', __FILE__)
 else
 puts "Booting Rails 2..."
 require File.expand_path('../boot2', __FILE__)
 end

Slide 15

Slide 15 text

server # config.ru ! require ::File.expand_path('../config/environment', __FILE__)
 
 if rails3?
 run FAVAdb::Application
 else
 use Rails::Rack::LogTailer
 use Rails::Rack::Static
 run ActionController::Dispatcher.new
 end
 # script/server ! #!/usr/bin/env ruby
 puts "Booting Rails 2..."
 require File.dirname(__FILE__) + '/../config/boot2'
 require 'commands/server'

Slide 16

Slide 16 text

routes & configure # boot.rb ! def draw_routes(&block)
 if rails3?
 FAVAdb::Application.routes.draw(&block)
 else
 ActionController::Routing::Routes.draw(&block)
 end
 end
 
 def configure(&block)
 if rails3?
 FAVAdb::Application.configure(&block)
 else
 yield
 end
 end

Slide 17

Slide 17 text

and more… • Rakefile • test_helper.rb script/server rake test ! RAILS3=1 rails s
 RAILS3=1 rake test

Slide 18

Slide 18 text

a plan • Boot Rails 3 • Click around until it breaks • (Capybara) tests for that section • Passing on Rails 2 & 3 • Repeat

Slide 19

Slide 19 text

long-term • Rails 3.0 • JQuery • Rails 3.2 and the asset pipeline • Ruby 1.9+ with sufficient test coverage • Strong parameters • Rails 4.x

Slide 20

Slide 20 text

Resources • https://github.com/discourse/discourse/ blob/master/Gemfile • http://railsdiff.org/ • https://speakerdeck.com/nathany/ upgrading-rails