home about

Upgrade to Rails 2.1.0_RC1

May 22nd, 2008 cpetersen

upgrayedd
upgrade (with 2 Ds)
Today seemed like a good day for an upgrade, so I decided to update our app to Rails 2.1.0_RC1. (The real reason is, I wanted to use has_one :through, but it wasn't in my version of Rails!)

I've detailed the steps I took to get our app up and running, this isn't an exhaustive list by any means, but I hope it helps.

Download Rails 2.1.0_RC1

Rail is on GitHub now, which is a great move. Unfortunately, our app is still under subversion and piston doesn't yet support Git, so I downloaded RC1 from http://github.com/rails/rails/commits/v2.1.0_RC1

Since I can't manage it with Piston anymore, I completely removed rails from my vendor directory and replaced it with the downloaded version.

Now its time to run

  rake spec
  
and see where we are.


STATUS: Dead in the water

ActionView::Base to ActionView::Template

At this point I can't even run rake, I just get the following error:

 
  ERROR
  > rake spec
  (in /Users/cpetersen/project)
  rake aborted!
  undefined method `register_template_handler' for ActionView::Base:Class

  (See full trace by running task with --trace)

It turns out we are registering a template handler for PDFs in our environment. Looks like they moved that functionality out of ActionView::Base into ActionView::Template, to fix all we needed to do is change the following line your config/environment.rb:

1
2
    ActionView::Base.register_template_handler 'pdf', ActionView::PDFRender
  
to:
1
2
    ActionView::Template.register_template_handler 'pdf', ActionView::PDFRender
  
and you can at least start running your specs again.


STATUS: LOTS of errors, 706 failures in 1014 tests

will_paginate

We use the wonderful will_paginate plugin to handle pagination in our app. However, when I run my specs, I now get the following:

  ERROR
  705)
  ActionView::TemplateError in 'CatalogController bin should show a compound'
  stack level too deep
  In catalog/compound.html.erb


      vendor/plugins/will_paginate/lib/will_paginate/finder.rb:138:in `method_missing_without_paginate'
      vendor/plugins/will_paginate/lib/will_paginate/finder.rb:139:in `method_missing'
      app/models/ware.rb:67:in `suggested_bins'
      spec/models/bin_spec.rb:32

It turns out, we weren't on the latest release. You can get the latest release here. Once again, its from the hub. The same process I used for installing Rails from github applies here.


STATUS: fewer errors, 30 failures in 1014 tests

acts_as_versioned

Not bad, the tests run, and only about 3% are failing. What next?

Almost all of the remaining errors look like this one:

  ERROR
  30)
  NoMethodError in '/survey_templates/edit should render survey template edit page'
  You have a nil object when you didn't expect it!
  You might have expected an instance of Array.
  The error occurred while evaluating nil.include?
  ./spec/views/survey_templates/edit.html.erb_spec.rb:6:in `new'
  ./spec/views/survey_templates/edit.html.erb_spec.rb:6:

We are using the acts_as_versioned plugin for versioning a lot of our content.

It turns out the core team has done a lot of work on "dirty" objects for this release. Ryan Daigle does a good job explaining it. It turns out this functionality breaks acts_as_versioned.

Luckily for us, codafoo is able to help. He forked acts_as_versioned and made it work with RC1 and dirty objects. You can get his version here. Since I had frozen acts_as_versioned into my vendor/gems directory, I just had to replace it with codafoo's version. Your milage may vary.

You'll notice, its GitHub once again. Note to self, switch to git.


STATUS: almost there, 2 failures in 1014 tests

Proper has_one Validation

Now we are getting down to some nitty gritty errors. It turns out my last two errors were only working before by accident.

Prior to RC1, has_one relationships weren't being validated properly on save. I apparently had my fixtures in an inconsistent state, causing my test to fail. My fault, RC1 helped me find a problem with my fixtures. Here is the ticket. I fixed my fixtures, and on to the next/last.


STATUS: last one, 1 failure in 1014 tests

Minor ActiveRecord::Base.find Change

Finally, there was a change to ActiveRecord::Base.find. I have a has_many :through relationship and I am doing a non-trivial find. I was including the table order_states and referencing its order_status_id column in my conditions. However, I wasn't including the table name in my conditions. Here's the code:

1
2
    @orders = Order.find(:all, :conditions => "order_status_id > 1", :include => "order_states", :order => "orders.created_at   DESC")
  
Prior to the RC1 upgrade that worked, but I should be using the table name. One more case of RC1 finding potential problems in my code. I changed it to:
1
2
    @orders = Order.find(:all, :conditions => "order_states.order_status_id > 1", :include => "order_states", :order => "orders.created_at DESC")
  
and it worked like a charm. I'm not sure what caused this change, but it may have been part of this change


STATUS: finished.

Thanks to Rob and Ryan for helping my through this process.

See you at RailsConf!

Update - attachment_fu

After I wrote this post, I realized that attachment_fu had stopped working (yet all the tests passed, troublesome). When I tried to upload something, I received the following stack trace:

NoMethodError (undefined method `after_attachment_saved_callback_chain' for #): /vendor/rails/activerecord/lib/active_record/base.rb:1645:in `method_missing_without_paginate' /vendor/plugins/will_paginate/lib/will_paginate/finder.rb:164:in `method_missing' /vendor/rails/activesupport/lib/active_support/callbacks.rb:272:in `send' /vendor/rails/activesupport/lib/active_support/callbacks.rb:272:in `run_callbacks' /vendor/rails/activerecord/lib/active_record/callbacks.rb:298:in `callback' /vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:377:in `after_process_attachment' /vendor/rails/activesupport/lib/active_support/callbacks.rb:173:in `send' /vendor/rails/activesupport/lib/active_support/callbacks.rb:173:in `evaluate_method' /vendor/rails/activesupport/lib/active_support/callbacks.rb:161:in `call' /vendor/rails/activesupport/lib/active_support/callbacks.rb:93:in `run' /vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `each' /vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `send' /vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `run' /vendor/rails/activesupport/lib/active_support/callbacks.rb:272:in `run_callbacks' /vendor/rails/activerecord/lib/active_record/callbacks.rb:298:in `callback' /vendor/rails/activerecord/lib/active_record/callbacks.rb:208:in `create_or_update' /vendor/rails/activerecord/lib/active_record/base.rb:2176:in `save_without_validation' /vendor/rails/activerecord/lib/active_record/validations.rb:901:in `save_without_dirty' /vendor/rails/activerecord/lib/active_record/dirty.rb:75:in `save_without_transactions' /vendor/rails/activerecord/lib/active_record/transactions.rb:106:in `save' /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction' /vendor/rails/activerecord/lib/active_record/transactions.rb:79:in `transaction' /vendor/rails/activerecord/lib/active_record/transactions.rb:98:in `transaction' /vendor/rails/activerecord/lib/active_record/transactions.rb:106:in `save' /vendor/rails/activerecord/lib/active_record/transactions.rb:118:in `rollback_active_record_state!' /vendor/rails/activerecord/lib/active_record/transactions.rb:106:in `save' /app/controllers/assets_controller.rb:54:in `create' /vendor/rails/actionpack/lib/action_controller/mime_responds.rb:106:in `call' /vendor/rails/actionpack/lib/action_controller/mime_responds.rb:106:in `respond_to' /app/controllers/assets_controller.rb:53:in `create' /vendor/rails/actionpack/lib/action_controller/base.rb:1161:in `send' /vendor/rails/actionpack/lib/action_controller/base.rb:1161:in `perform_action_without_filters' /vendor/rails/actionpack/lib/action_controller/filters.rb:580:in `call_filters' /vendor/rails/actionpack/lib/action_controller/filters.rb:601:in `run_before_filters' /app/controllers/application.rb:17:in `set_current' /vendor/rails/activesupport/lib/active_support/callbacks.rb:173:in `send' /vendor/rails/activesupport/lib/active_support/callbacks.rb:173:in `evaluate_method' /vendor/rails/actionpack/lib/action_controller/filters.rb:395:in `call' /vendor/rails/actionpack/lib/action_controller/filters.rb:598:in `run_before_filters' /vendor/rails/actionpack/lib/action_controller/filters.rb:578:in `call_filters' /vendor/rails/actionpack/lib/action_controller/filters.rb:573:in `perform_action_without_benchmark' /vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' /vendor/rails/actionpack/lib/action_controller/rescue.rb:201:in `perform_action_without_caching' /vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'

The solution for us was just to update attachment_fu to trunk. Voila, everything started working again.

3 Responses to “Upgrade to Rails 2.1.0_RC1”

  1. Daniel Insley Says:
    Thanks for the post, saved us some time!
  2. Matthew Wilson Says:
    By "update attachment_fu to trunk" do you mean running the following? script/plugin update attachment_fu I tried that and no changes came down and problem remained...
  3. Frank Beard Says:
    Thanks for the post... especially the info about acts_as_versioned

Leave a Reply