Skip to content

Commit

Permalink
Upgrade ruby and rails (#868)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/RUBY-1061

This PR contails all the changes necessary to upgrade the Ruby version from 2.4 to 2.7.1 and Rails version from 4.2 to 6.0.3.1

Some notes about the updates:
- Request tests syntax for params and headers to send along with a `get`, `put` or `post` request have changed. Now the params are into a key-value format with the key specifying what are `params` and what are `headers`
- With Rails 6, the `rake` command is not invoked directly any more. Instead, we now use `bin/rails`.
- Since Rails 6 was built with the. intent to leave the assets work to. NodeJs, we had to require the `sassc-rails` gem on top of the rest of the gems in order for the old way of dealing with assets still works.
- `POST` request that do not specify a render will redirected to a `GET` automatically, hence we have to explicitly raise errors now if we want them not to be reachable
- Inherithance and scoping are something we must make more attention too. We used to define stuff like:
```
module WasteCarriersEngine
  class ErrorsController < ApplicationController
```
and trust that ruby would resolve the `ApplicationController` to be the module-scoped definition of it. We can't trust that any more, hence we have to be specific and do stuff like:
```
module WasteCarriersEngine
  class ErrorsController < ::WasteCarriersEngine::ApplicationController
```
- Parameters on controller coming from a request are not any more instances of the Hash class, but instances of the `ActionController::Parameters` class
- The test suite will run in `:random` mode by default
- Many of the spec matches we were used to in request tests have been externalised to a gem `rails-controller-testing`
  • Loading branch information
cintamani committed Jun 26, 2020
1 parent 8730699 commit 41a1997
Show file tree
Hide file tree
Showing 162 changed files with 447 additions and 372 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.2
2.7.1
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ addons:
organization: "defra"

language: ruby
rvm: 2.4.2
rvm: 2.7.1
cache: bundler

# Travis CI uses shallow clone to speed up build times, but a truncated SCM
Expand Down Expand Up @@ -40,7 +40,7 @@ services:

before_install:
- export TZ=UTC
- gem install -v 1.17.3 bundler
- gem install bundler
- sudo apt-get install xvfb -y
- sudo apt-get install ttf-liberation -y
- sudo apt-get install wkhtmltopdf -y
Expand Down
13 changes: 9 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# frozen_string_literal: true

source "https://rubygems.org"
ruby "2.4.2"
ruby "2.7.1"

# Temporary workaround until we implement webpack assets
# See: https://github.com/sass/sassc-rails/issues/114
gem "sassc-rails"

# Declare your gem's dependencies in waste_carriers_engine.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
Expand All @@ -16,7 +20,7 @@ gem "govuk_template", "~> 0.23"
gem "jquery-rails"

# Use MongoDB as the database
gem "mongoid", "~> 5.2"
gem "mongoid"
# Implement document-level locking
gem "mongoid-locker"

Expand All @@ -38,12 +42,12 @@ group :development, :test do
# Apply our style guide to ensure consistency in how the code is written
gem "defra_ruby_style"
gem "dotenv-rails"
gem "rspec-rails", "~> 3.6"
gem "rspec-rails"
end

group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem "web-console", "~> 2.0"
gem "web-console"

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem "spring"
Expand All @@ -57,6 +61,7 @@ end
group :test do
gem "database_cleaner"
gem "factory_bot_rails", require: false
gem "rails-controller-testing"
gem "simplecov", "~> 0.17.1", require: false
gem "timecop"
gem "webmock", "~> 3.4"
Expand Down
Loading

0 comments on commit 41a1997

Please sign in to comment.