Tuesday, September 28, 2010

Migrating rails app from 2.2.2 to 2.3.5

I recently migrated my rails app from rails version 2.2.2 to 2.3.5. I enjoyed the work as it was a good learning for me. Listing the steps that I followed and some issues that I faced during the migration.

Gems installed on my windows machine :-

mongrel (1.1.5 x86-mingw32)
rake (0.8.7)
rack (1.0.1)
rubygems-update (1.3.7)


(1) I installed rails :-

gem install rails -v=2.3.5

(2) Deleted rails folder (2.2.2) from app/vendor.

environment.rb file -

RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION


Go to the project root and execute :-

rake rails:update --trace

It will update some js files and also renames application.rb to application_controller.rb

** Invoke rails:update (first_time)
** Invoke rails:update:scripts (first_time)
** Execute rails:update:scripts
** Invoke rails:update:javascripts (first_time)
** Execute rails:update:javascripts
** Invoke rails:update:configs (first_time)
** Execute rails:update:configs
** Invoke rails:update:application_controller (first_time)
** Execute rails:update:application_controller
app_root/app/controllers/application.rb has been renamed to app_root/app/controllers/application_controller.rb, update your SCM as necessary
** Execute rails:update

(3) Rename application_spec.rb to application_controller_spec.rb

(4) Localize rails version into the app.

rake rails:freeze:gems

(5) I was having rspec(1.2.3) and rspec-rails(1.2.3) plugins which I removed and installed rspec(1.3.0) and rspec-rails(1.3.0) gems instead and then localized in the app/vendor.

gem install rspec -v 1.3.0
gem install rspec-rails -v 1.3.0


environment.rb file :-

config.gem "rack", :version => "1.0.1"
config.gem "rspec-rails", :lib => false, :version => ">= 1.3.0"
config.gem "rspec", :lib => false, :version => ">= 1.3.0"


Go to the project root and execute :-
rake gems:unpack

(6) I kept a copy of my customized spec/spec_helper.rb file because I wanted to run "ruby script/generate rspec" for upgrading rspec-rails in the app which overwrites these three files :-

* spec/spec.opts
* spec/rcov.opts
* spec/spec_helper.rb

(7) While running the specs, I got flash.now[:message] specs failing.

I added following in the spec/spec_helper.rb file to fix the issue with that spec.

module DisableFlashSweeping
def sweep
end
end


module EnableFlashSweeping
def sweep
keys.each do |k|
unless @used[k]
use(k)
else
delete(k)
@used.delete(k)
end
end
# clean up after keys that could have been left over by calling reject! or shift on the flash
(@used.keys - keys).each{ |k| @used.delete(k) }
end
end


And I used the calls in the spec before the action as :-

it 'should retain the flash message only for the current request' do
controller.instance_eval { flash.extend(DisableFlashSweeping) }
post :create, :work_loc => {:country => "India", :state => "Maharashtra"}
response.should be_success
flash[:message].should == "Error in Loc mapping!"
end


(8)
I changed in rspec from

response.should render_template(:states) '
TO
controller.should_receive(:render).with(:partial => 'states')

(9) Changed response.headers["Status"] to response.status in some of the controller specs.

(10) I got one deprecation warning about formatted_url :-

DEPRECATION WARNING: formatted_action_name_controller_name_url() has been deprecated. Please pass format to the standard action_name_controller_name_url method instead..

So changed :action from
:action => formatted_action_name_controller_name_url('js')
to
:action => action_name_controller_name_url(:format => 'js')

Now, along with the rspecs, my app is looking good with rails 2.3.5

Planning to go ahead with migrating to 2.3.9 to make the app more closer to Rails 3.0.

No comments:

Post a Comment