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_assets
is deprecated. Instead you need to set the environment variableRAILS_SERVE_STATIC_FILES
totrue
in 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.parse
and force an exception but found that thebegin...rescue
around the code then didn't trap the exception. I moved the parsing to a separate method then stubbed the new method. - Routing:
route_to
expectations now seem to include the parameters passed to the route - Controller specs: You need to explicitly set the
method
when doing acall
- Controller specs: With
assigns
expectations you can only match the whole instance variable, not components of it, e.g.expect(assigns(:avatar)['images'][0]['image']).to eq avatar
doesn't work any more (I had to use theinclude
matcher instead ofeq
)
- Scopes need to be procs, e.g.
scope :email, where(service: 'email')
becomesscope :email, -> { where(service: 'email') }
- You can't
touch
an 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.parse
will only accept a string. You can't parse something that's already a date or time.
- Resourceful routing syntax:
get :company, to: :company
gives 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.