Rails 4.1 upgrade from 4.0

April 16, 2014

We have just upgraded a rails 4.0 application to Rails 4.1. It has a PostgreSQL DB; is developed on Windows; and is run in production on Linux in  AWS.   All rspec tests were passing and on rails 4.0 prior to the upgrade. On setting the rails version to 4.1, we had some test failures.

Here are the fixes made:

  1. Timezone error:
n `rescue in create_default_data_source': No timezone data source could be found. To resolve this, either install TZInfo::Data
(e.g. by running `gem install tzinfo-data`) or specify a zoneinfo directory using `TZInfo::DataSource.set(:zoneinfo, zoneinfo_path)`.

Fix:  Add this to the gem file:

gem 'tzinfo-data', platforms: [:mingw, :mswin]
  1. Model “belongs_to” association reserved word conflict.
`build': You tried to define an association named transaction on the model Holding, but this will conflict
with a method transaction already defined by Active Record. Please choose a different association
name. (ArgumentError)

Fix:  use an alias for the association, and change references in this model. The changes were limited to just this model.

#belongs_to :transaction
belongs_to :trade, :foreign_key => 'transaction_id', :class_name => "Transaction"
  1. pg_search SQL error when calling  “.count” on the result.
PG::SyntaxError: ERROR: syntax error at or near "AS"
LINE 1: ...name') || ' ''' || ':*')), 0))) AS pg_search_rank AS count_c...

Fix:  Use .count(:all) instead of .count

( We also replaced will_paginate with kaminari, but dont know if this is required to fix this issue )

4) Preloader initialization now takes no arguments

Fix: changed this:

ActiveRecord::Associations::Preloader.new(result, foo: :bar).run

to this:

preloader = ActiveRecord::Associations::Preloader.new()
preloader.preload(result, foo: :bar)

5) number_to_currency is now html escaping options

Fix: change this:

number_to_currency(number, options = { :unit => "£" } )

to this:

number_to_currency(number, options = { :unit => "£".html_safe() }
  1. Some “show new” view tests failed due to the path on the form partial routing to Controller#show instead of Controller#new.
ActionView::Template::Error No route matches {:action=&gt;"show", :controller=&gt;"foo", :id=&gt;nil}</code>

Fix: pluralise the model name

change this:

<%= simple_form_for( foo, url: foo_path(foo) ) do |f| %>

to this:

<%= simple_form_for( foo, url: foos_path(foo) ) do |f| %>

© 2020 Keith P | Follow on Twitter | Git