Whenever I upgrade Rails, I always start with “rails new” so that I get all the new config file goodness — I want to start fresh with whatever the new defaults are and then only make the modifications that I really want in my app. Here’s the process I went through upgrading the pie “bakery” (a relative simple Rails 3.0 app) to Rails 3.1.

First I moved my old app to a new name (since I want my new Rails app to have the same name internally as the old Rails app):

mv bakery bakery30

Now I set up a new gemset, so I’m starting fresh. (My first attempt was to use my old gemset, but that showed me an old warning that I’d like to not bring forward, or at least isolate in the process of upgrading):

rvm use 1.9.2-p290
rvm gemset create rails31
rvm use 1.9.2-p290@rails31

Create the new app (specifying -T to create the app without test-unit, since I’m an RSpec fan)

rails new bakery -T
mv bakery bakery 31

Now I edit my Gemfile to include the gems I want to bring over from my old app…

cd bakery
vi Gemfile   
bundle install

Then I want to re-generate rspec and cucumber config files and boilerplate

rails g rspec:install
rails g cucumber:install

ok, now I have vanilla Rails 3.1 app
I fetch my old app from github:

git clone git@github.com:blazingcloud/pie-bakery.git bakery
cd bakery

and using the power of git, I’m going to remove all the old 3.0 code, add in my 3.1 app

git rm -r *
cp -r ../bakery31/* .
git add .

Then I use gitx (a modern version like brotherbard) to look at the changes and revert any deletes that are actually app code that I want to keep, review every diff, and hope that I’m paying close enough attention to everything (really wish I could be pairing on this).

Now I set up my database and run my tests… I don’t know why “rake test” doesn’t automatically run cucumber and rspec tests like it used to. hmmm

rake db:schema:load
rake cucumber
rake spec

I realize that I missed a couple of diffs, rinse, repeat… when all is green I’m done. Whew.

I copy in my old .git/config so I pull in my remote heroku repo config (which I’ve updated to cedar stack)

cp ../bakery30/.git/config .git/config

and run rails

I really want to upgrade a Rails 3.0 project to Rails 3.1, but I’ve done a few spikes and it lacks test coverage, so I decided to pull in cucumber and write some features before moving forward.

I added cucumber-rails to my gemfile, and ran “bundle” and got this error:

/Users/sarah/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:289:in `load': uninitialized constant Psych::Syck (NameError)

What I really needed was to update my Ruby Gems (bundle update –system) but before I discovered that I did “bundle update” which moved me forward to rake 0.9.2, so I started getting these warnings:

/Users/sarah/.rvm/gems/ruby-1.9.2-p290@pie-bakery/gems/psych-1.2.1/lib/psych.rb:93: warning: already initialized constant VERSION
/Users/sarah/.rvm/gems/ruby-1.9.2-p290@pie-bakery/gems/psych-1.2.1/lib/psych.rb:96: warning: already initialized constant LIBYAML_VERSION
WARNING: Global access to Rake DSL methods is deprecated.  Please include
...  Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method Bakery::Application#task called at /Users/sarah/.rvm/gems/ruby-1.9.2-p290@pie-bakery/gems/railties-3.0.0/lib/rails/application.rb:214:in `initialize_tasks'

So, I’ve learned from google, stackoverflow, various blogs and my twitter friend @excid3 that I need to update my Rakefile to include:

require 'rake/dsl_definition'
require 'rake'
include Rake::DSL

That lets me use rake (yay!). I still have the following two warnings:

/Users/sarah/.rvm/gems/ruby-1.9.2-p290@pie-bakery/gems/psych-1.2.1/lib/psych.rb:93: warning: already initialized constant VERSION
/Users/sarah/.rvm/gems/ruby-1.9.2-p290@pie-bakery/gems/psych-1.2.1/lib/psych.rb:96: warning: already initialized constant LIBYAML_VERSION

which I’m hoping will go away with the Rails 3.1 upgrade, but I thought I would write up the rest of it in case it helps other wayward souls on their journey.