Last Updated: February 25, 2016
·
2.068K
· damax

From 4.2 to 5.0 Rails migration [Part 1]

The post will cover my experience. So, my experience, my project, my migration. It won't be the same for you.

Rails 5 still in beta 1 when I made the migration.

As addationnal gems to Rails, the project have:

  • cancancan
  • devise
  • devise-i18n
  • puma
  • rolify
  • autoprefixer-rails
  • simple_form
  • slim-rails

At that point tests doesn't even run.

By the way, I have 78 tests.


Devise

devise-3.5.3/lib/devise/failure_app.rb:9:in `<class:FailureApp>': uninitialized constant ActionController::RackDelegation (NameError)

It's due to the removal of RackDelegation. It seems it was used for request and response object. It exists now in all controllers.
The PR that remove it.
The ticket issue in the tracker.

The solution is to use the master branch on Github.

gem 'devise', github: 'plataformatec/devise', branch: 'master'

At that point, the test can run ... with a errors but run.

=> 78 examples, 23 failures


Failure/Error: expect(assigns(:organisations)).to eq(organisations)
 NoMethodError:
   assigns has been extracted to a gem. To continue using it,
           add `gem 'rails-controller-testing'` to your Gemfile.

Self explained. Added that gem.

=> 78 examples, 23 failures

That's strange. It doesn't solve the problem. The issue seems to come from RSpec.


Let's update RSpec to the master branch (the latest doesn't support Rails 5 yet).

%w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
  gem lib, github: "rspec/#{lib}", branch: 'master'
end

It's installing a very old version (1.x instead of 4.x) of guard-rspec. No new version yet, let's remove it for now.

=> 78 examples, 8 failures


You'll need to update web-console to version 3

=> 78 examples, 6 failures


Error from routes helper "*_path"

ActionView::Template::Error:
   undefined local variable or method `organisations_path' for #<#<Class:0x007ff526bd7248>:0x007ff52abae2e0>

In the console, it exists:

[4] pry(main)> app.organisations_path
=> "/organisations"

Still have the error, let's keep it for now.

Remark: even with this error the application seems to work correctly.

Let's remove the deprecating warnings noises.

Deprecations fixes

ActionController::TestCase HTTP request

The message:

DEPRECATION WARNING: ActionController::TestCase HTTP request methods will accept only
keyword arguments in future Rails versions.

Examples:

get :show, params: { id: 1 }, session: { user_id: 1 }
process :update, method: :post, params: { id: 1 }

For me, it was mostly changing from:

get :homepage, {}

to:

get :homepage, params: {}