Rails 2.3 Upgrade Problems and Solutions

Posted by sudothinker on March 01, 2009

Cucumber

This fix will address “undefined method `visits’ for # (NoMethodError)”

# features/env.rb

require 'webrat/rails'
Webrat.configure do |config|
  config.mode = :rails
end

Gems

This fix will address “uninitialized constant RedCloth (NameError)”

# config/environment.rb

config.gem "RedCloth", :lib => "redcloth", :source => "http://code.whytheluckystiff.net" 
rake gems:unpack
rake gems:build

Forms

Fields for now should be called on the outter form, before I had

fields_for 'video[ingredient_attributes][]', ingredient do |i_form|

which used the Multimodel Forms plugin.

Now this becomes:

video_form.fields_for :ingredients do |i_form|

See http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes for more information.

Try

The version of try I had was this:


class Object
  def try(method)
    send method if respond_to? method
  end
end

in rails 2.3 though the try method is changed to this:


class Object
  def try(method, *args, &block)
    send(method, *args, &block)
  end
end

class NilClass
   def try(method, *args, &block)
     nil
   end
end

So I got a bunch of undefined method errors which I had to change around to use respond_to, or move the try up the chain so it gets called on nil.

SimplyHelpful

Get rid of this, the functionality has been added to rails. You might see “uninitialized constant SimplyHelpful::Record Identifier (ActionView::TemplateError)” otherwise.

route_for

After a change to edge rails broke our monkey-patched #route_for method, I decided to just delegate to rails’ #assert_generates method. For most cases, this will not present a problem, but for some it might. You’ll know if you upgrade and see any newly failing, route-related examples. Here are the things that you might need to change.

  • Make sure IDs are strings

If you had :id => 1 before, you need to change that to :id => “1”


#old
route_for(:controller => 'things', :action => 'show', :id => 1).should == "/things/1" 

#new
route_for(:controller => 'things', :action => 'show', :id => "1").should == "/things/1" 
  • Convert paths for non-get methods to hashes

If you had an example with a route that requires post, put, or delete, you’ll need to declare that explicitly.


#old
route_for(:controller => 'things', :action => 'create').should == "/things" 

#new
route_for(:controller => 'things', :action => 'create').should == {:path => "/things", :method => :post}

assert_select

I was using assert_select (should have_tag) in rspec in model specs to verify to_xml representations of models. This isn’t really recommended as have_tag should really only be used for html. Instead I used Hpricot to parse the xml (Hpricot.XML) and then verified the contents of the hpricot object.

Comments

Leave a response

  1. Darren HindererMarch 13, 2009 @ 02:47 PM

    Thanks for the RedCloth tip, although I had to do the build step before the unpack.

  2. Jason GarberMarch 17, 2009 @ 01:10 AM

    What version of RedCloth are you getting from code.whytheluckystiff.net? Probably not the latest.

    config.gem “RedCloth” should be all you need for RedCloth 4.1.9

Comment