I Googled an upgrade guide and read two or three before starting. Useful information.
This page just lists the things I didn't find in the upgrade guides.
- Static files Rails 4.2 doesn't serve static files by default, and
config.serve_static_assetsis deprecated. Instead you need to set the environment variableRAILS_SERVE_STATIC_FILEStotruein the production environment.
I upgraded to Rspec 3.2. Things to note:
- Stubbing a class you don't own can give unexpected results. I wanted to stub
JSON.parseand force an exception but found that thebegin...rescuearound the code then didn't trap the exception. I moved the parsing to a separate method then stubbed the new method. - Routing:
route_toexpectations now seem to include the parameters passed to the route - Controller specs: You need to explicitly set the
methodwhen doing acall - Controller specs: With
assignsexpectations you can only match the whole instance variable, not components of it, e.g.expect(assigns(:avatar)['images'][0]['image']).to eq avatardoesn't work any more (I had to use theincludematcher instead ofeq)
- Scopes need to be procs, e.g.
scope :email, where(service: 'email')becomesscope :email, -> { where(service: 'email') } - You can't
touchan object until it's persisted find_or_create_by_...needs to be changed to equivalentfirst_or_create- Select/Pluck: This gives an error:
SourceContact.all(select: :id). This is fine:SourceContact.all.pluck(:id)
Time.parsewill only accept a string. You can't parse something that's already a date or time.
- Resourceful routing syntax:
get :company, to: :companygives a warning unless you change it toget :company, action: :company
I found one gem that didn't work with Rails 4, but I was deliberately using a very old version because the new one didn't do what I wanted.