December 2010
Rails 2 -> 3 Case Study: Deltacloud
Submitted by mmorsi on Fri, 2010-12-17 03:26
Over the last few days I spent a little while updating Deltacloud from Rails 2 -> 3. The patchset is largely done, our application itself is fully functional, as is the spec suite, though there is a little more to do concerning getting some of our cucumber tests back to a functional state.
The upgrade process itself was fairly straightforward, I started off by creating a new project, then went through the newly created sources, copying the ones over which I could as is, merging the ones that affected files which we've changed. Overall the process is simple, though there were a bunch of nits involving doing things the new way and getting around deprecation warnings and such.
I'm also glad to say that all the upstream communities which develop and support gems we depend on seem to be on the ball, and while the rpms in Fedora need to be updated, the upstream gems all already support Rails 3. Authlogic is a small exception as it does work w/ Rails 3 but using it results in many ugly deprecation warnings in the logs. To get around these, I had to make the following changes to the authlogic gem itself (all files changes are in /usr/lib/ruby/gems/1.8/gems/authlogic-2.1.6/)
- lib/authlogic/session/callbacks.rb: s/save_without_session_maintenance(false)/save_without_session_maintenance(:validate => false)
- lib/authlogic/acts_as_authentic/password.rb: s/save(false)/save(:validate => false)
- lib/authlogic/acts_as_authentic/logged_in_status.rb: s/named_scope/scope
All in all here are the following changes that had to be made to our application to make it Rails 3 compliant:
-
Framework Changes (taken care of when you create a new rails 3 project):
- new versions of the public/*.html and public/dispatch* files
- all scripts have been placed with script/rails
- prototype.js, rails.js, and other javascripts have been updated
- Bundler is now being used to manage dependencies, remove gems from environment.rb (and specific environments/* config files) and move into Gemfile and Gemfile.lock
- Alot of the configuration api has been updated and you will need to change the various files in config/ to reflect this
- The Routing API has been overhauled, config/routes.rb will need some significant changes, but the nice thing is you can verify your routes w/ 'rake routes'
-
Application Changes:
- "filter_parameter_logging" is now being taken care of in the configuration
- "master_helper_module.module_eval" has been replaced by "class_eval" and "helper_method"
- "log_error" is no longer supported, replaced w/ the rails logger
- "request.request_uri" has been replaced w/ "request.fullpath"
- "before_filter" no longer takes an array, rather it just needs to be called multiple times
- I had to change "dispatch" in our templates controller to "dispatch_action" as the former was conflicting with a method added to all the controllers by rspec
- "WillPaginate::LinkRender" is now "WillPaginate::ViewHelpers::LinkRenderer"
- "named_scope" is deprecated, now simply use "scope"
- overriding the "validate" method is now deprecated, rather custom validation methods need to be registered
- "RAILS_ROOT" has now been replaced w/ "::Rails.root.to_s"
- In haml, the "-" operator has been deprecated, rather everything is now handled by "=" whether it outputs anything or not
- form.error_messages_on no longer simply just take text to prepend but rather a hash of which text to prepend/append/etc
-
Test Changes:
- Various changes to paths and urls to work w/ the new routing api
- The cucumber and rspec rake tasks have been updated
- All the specs need to "include Authlogic::TestCase" to make use of authlogic
- The "route_for" test helper has been replaced w/ 'route_to'
- The activerecord 'destroy' method no longer returns false, but an empty array (at least from my findings)
- Mock('foo', :null_object => true) has been replaced with mock('foo').as_null_object
- Activerecord errors do not support the 'on' method anymore (at least its deprected) rather you can access errors on specific fields by passing that field name as a hash key, which will return an array of errors
For reference here is the patchset updating Deltacloud to Rails 3. I can't push the changes to our codebase until Rails 3 is in Fedora with all the gems that depend on it, but the tentative goal is to do so by Fedora 15 (we have done some preliminary work to update the rpms on this front, but there is still a ways to go, help is always appreciated).
- Intro
- Rails 2->3 framework changes, nothing specific to deltacloud
- prototype.js and rails.js updates, also 100% rails, nothing specific to deltacloud, but large enough to justify their own patch
- gem dependency changes, introduces Gemfile for bundler
- deltacloud rails 3 config changes
- deltacloud rails 3 application changes
- deltacloud rails 3 views changes
- deltacloud rails 3 spec/cucumber changes
- misc changes
Hope this helps anyone looking to upgrade. It is a bit of a process, but the new Rails 3 changes are nice and look like they make more things consistent. Enjoy!
- mmorsi's blog
- Login to post comments
- Read more





