on
Rails 3 Upgrade Resources
Many of us have several existing 2.x applications and would want to upgrade without pulling our hair because we can’t figure out something or we are wary of consuming too much time. I’m about to post several links where you could find useful advice on upgrading Rails 3. Feel free to share other links if you know some.
Question: is it worth it to upgrade?
It’s definitely worth it. There is no logical reason for staying “behind” (other than money).
Obviously, an application that has a test suite or has been developed using TDD (Test-Driven Development) or BDD (Behaviour-Driven Development) is much is easier to upgrade than apps that don’t.
What has changed in RSpec for Rails 3? Not much.
In Rails 2.x, we have this functional test:
require 'spec_helper'
describe PostsController do
integrate_views
fixtures :posts
fixtures :users
setup :activate_authlogic
def mock_post(stubs={})
@mock_post ||= mock_model(Post, stubs).as_null_object
end
describe "GET index" do
before do
require_admin
end
it "assigns all posts as @posts" do
Post.stub(:all) { [mock_post] }
get :index
assigns(:posts).should eq([mock_post])
end
end
end
If we’d like it to work for Rails 3, we just need to change one thing.
require 'spec_helper'
describe PostsController do
render_views
fixtures :posts
fixtures :users
setup :activate_authlogic
def mock_post(stubs={})
@mock_post ||= mock_model(Post, stubs).as_null_object
end
describe "GET index" do
before do
require_admin
end
it "assigns all posts as @posts" do
Post.stub(:all) { [mock_post] }
get :index
assigns(:posts).should eq([mock_post])
end
end
end
I really appreciate that many developers share their experience on how they successfully upgraded their applications to 3.x. One of them is Greg Moreno. He is founder of Propsify. He’s a Filipino developer based in Canada who’ll come back to the Philippines in September for RailsJam events. Please find time to check out the website (which I designed) for details about the events:
These are the most useful and concise posts I’ve seen on upgrading a 2.x app to 3.x:
Rails 3 upgrade part 1: Booting the application
Rails 3 upgrade part 2: Routes
Rails 3 upgrade part 3: Code fixes, views, and forms
I also find the Rails 3 Upgrade handbook PDF (not free) very useful. It’s like a manual that shows everything (or nearly everything) that’s deprecated in Rails 3.
Also Rails 3 works well or better for Ruby 1.9.2. So you have to install RVM to use with 1.9.2 version.
Someone asked me this, what is “g” in Rails 3?
It’s simply an alias for “generate.”
rails g
Usage: rails generate GENERATOR [args] [options]
General options:
-h, [--help] # Print generators options and usage
-p, [--pretend] # Run but do not make any changes
-f, [--force] # Overwrite files that already exist
-s, [--skip] # Skip files that already exist
-q, [--quiet] # Supress status output
Please choose a generator below.
Rails:
controller
generator
helper
integration_test
mailer
migration
model
observer
performance_test
plugin
resource
scaffold
scaffold_controller
session_migration
stylesheets
Authlogic:
authlogic:session
authlogic:session
Cucumber:
cucumber:feature
cucumber:install
Datamapper:
datamapper:migration
datamapper:model
datamapper:observer
Erb:
erb:controller
erb:mailer
erb:scaffold
Erubis:
erubis:controller
erubis:scaffold
FactoryGirl:
factory_girl:model
Formtastic:
formtastic:scaffold
FriendlyId:
friendly_id
Haml:
haml:install
Jquery:
jquery:install
Koala:
koala:install
Machinist:
machinist:model
Mongomapper:
mongomapper:model
mongomapper:observer
Mustache:
mustache:controller
mustache:install
mustache:scaffold
Rspec:
rspec:install
Shoulda:
shoulda:controller
shoulda:model
SimpleForm:
simple_form:scaffold
TestUnit:
test_unit:controller
test_unit:helper
test_unit:integration
test_unit:mailer
test_unit:model
test_unit:observer
test_unit:performance
test_unit:plugin
test_unit:scaffold
Hope this was useful.