Upgrading your Rails 3.0.3 application

Problem
After the announcements in the previous posts about the security vulnerabilities in Rails 3.0.3, you would like to update your application and deploy with the latest 3.0.4 version.

Solution

  • Change your Gemfile to replace
    gem 'rails', '3.0.3'
    with
    gem 'rails', '3.0.4'
  • Run:
    bundle update rails
  • Remove the old gems by using:
    git status
    and then
    git rm name_of_3.0.3_gem
  • Add the new gems to your git
    git add vendor/cache
  • Check in to your repository the new files
    git commit vendor/cache -m 'upgrade to rails 3.0.4'
  • Make sure that you also check in both your Gemfile and Gemfile.lock into your git repository
    git commit Gemfile Gemfile.lock -m 'update Gemfiles to use 3.0.4'
    otherwise when you try to deploy you will see the error:
    You have modified your Gemfile in development but did not check the resulting snapshot (Gemfile.lock) into version control
  • push everything to your git repository:
    git push
  • Deploy your application with capistrano as usual:
    cap deploy
  • Your new gems for 3.0.4 should be installed on the share/bundle folder

no such file to load — readline (LoadError) – Rails 3.0.3 console – rvm

Problem

When you try to run the console rails c in a new Rails 3.0.3 application, and when you use rvm, you get the following error:

no such file to load -- readline (LoadError)

Solution

It’s quite like likely that the readline libraries are missing from your installation. To find out which ones go to the directory that the error is indicating (ie):

cd ~/.rvm/rubies/ruby-1.8.7-p299

and then to the following:

cd ext/readline

then run the following:

ruby extconf.rb

If you get something like:
checking for readline/readline.h... no
checking for editline/readline.h... no

then you are probably missing the neccessary header files for readline.
so install them in your system (ie in Mandriva):

sudo urpmi readline-dev,

In Debian you will need to install libreadline5-dev and maybe libncurses5-dev (apt-get install).

When the package is installed successfully run the following again:

ruby extconf.rb
make
sudo make install

You should now be able to go back to your project and run rails c with no errors.

undefined method `visit’ for # (NoMethodError)

Problem
When using Cucumber and Webrat in a ruby on rails 3 application you see the error: undefined method `visit' for # (NoMethodError) and your scenario fails.

Solution
Replace the line:
config.mode = :rails
with the line:
config.mode = :rack
in the Webrat.configure block, in your
app/features/support/env.rb
file.

Adding Webrat, Cucumber and RSpec to a new Rails 3 project

Problem

You would like to start using BDD in a new Ruby on Rails 3 application, and would like to install Webrat, Cucumber and RSpec to your project.

Solution

Follow the steps below (taken from the RSpec Book), for creating a new Rails 3 application and adding the necessary testing frameworks:

  1. Create your new ruby on rails application: rails new my_app
  2. Go to your new application directory: cd my_app
  3. Edit your Gemfile to include the following:
    group :development, :test do
    gem "rspec-rails", ">= 2.0.0"
    gem "cucumber-rails", ">= 0.3.2"
    gem "webrat", ">= 0.7.2"
    end
  4. Use bundler to install all the gems and dependencies: bundle install
  5. Install the rspec files: script/rails generate rspec:install
  6. Install the cucumber files: script/rails generate cucumber:install
  7. Run the following and you shouldn’t be seeing any errors:
    rake db:migrate
    rake db:test:prepare
    rake spec
    rake cucumber