1

I've inherited an old project from another dev which runs on Ruby 1.8 and uses Rails 2. I'm very new to Ruby and Rails project so I wanted to get advice about upgrading such types of project. One major problem with this project is that it has not test coverage. No unit tests at all. Here is some project stats:

$ cloc .

http://cloc.sourceforge.net v 1.56  T=3.0 s (149.3 files/s, 15714.0 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Ruby                           379           3106           1476          15246
Javascript                      18           2981           2369          11008
CSS                             16            690           1208           7156
HTML                            21            324             69           1039
YAML                            13             46            164            236
Bourne Shell                     1              2              5             17
-------------------------------------------------------------------------------
SUM:                           448           7149           5291          34702
-------------------------------------------------------------------------------

My plan is to start a new Rails project and write tests see theme fail and then bit by bit bring in old code, update the parts that need updating and go forward.

Is this as daunting as I've been told? Is the above approach realistic? What are some pitfalls I should look out for?

Roman
  • 10,309
  • 17
  • 66
  • 101

2 Answers2

2

I have done this myself, recently; I migrated a Rails 2.3 project through Rails 3.0 and 3.1 before ending up in 3.2. It was a bit daunting, but my observations:

  1. I started off trying to create a new project, like you suggest - but I quickly decided against it, and went back to just updating the existing project.
  2. I found the RailsCasts on migrating to Rails 3 to be extremely useful. The first one is here: http://railscasts.com/episodes/225-upgrading-to-rails-3-part-1
  3. If you're going to be writing tests anyways (which is ABSOLUTELY the right thing to do), I found it easiest to start this AFTER upgrading to 3.0. There were several issues around compatible versions of testing gems, as I recall, between 2.3 and 3.0. My favourite testing environment involves RSpec, Cucumber, and Guard. This RailsCast is awesome for setting up testing: http://railscasts.com/episodes/275-how-i-test
  4. Version control is your friend. I made a git branch for each major point release that I worked through. That way, when I borked something badly, I could easily scrap the branch and try again.

The long and short of it - it's doable, but it'll take some time to get it right. Starting over with a "fresh" project, in my case at least, turned out not to be necessary or helpful.

drosboro
  • 398
  • 1
  • 9
1

Hm..I thinks it's not a best idea, better upgrade to latest stable 2.x release, which is currently 2.3.15.

But if you want to do this anyway, may be these article can help you:

http://www.railsdispatch.com/posts/upgrading-a-rails-2-app-to-rails-3

http://net.tutsplus.com/tutorials/ruby/5-awesome-new-rails-3-features/

Migrating from Rails 2 to Rails 3

and also this plugin:

https://github.com/rails/rails_upgrade

Community
  • 1
  • 1
Bob
  • 2,081
  • 18
  • 25
  • Because there are too many changes in Rails 3, without tests it may be very painful)) – Bob Jan 25 '13 at 13:13