CNK's Blog

Migrating to Rails 4.1 - Part 1

For a variety of reasons we postponed upgrading our custom CMS from Rails 2 to 3 for …. quite a while. Migrating on the bleeding edge is hard - but so is being so far behind. In particular, the advice to upgrade step by step, using the rails rake tasks to automate some things, doesn’t really work because it is too difficult to figure out compatible sets of plugins. For one thing, my testing frameworks have undergone drastic changes. So even if I can automate upgrading rails, I can’t run the tests to verify the upgrades. So I am going to just start over with the current version of rails: 4.1.0.

Using RVM, ruby-1.9.3-p484, and a fresh gemset (empcms4), I generated a new project. I don’t think turbolinks is going to be especially useful, so I removed it. I really like shoulda, so that’s a must. I am less adamant about test framework. I generally prefer the minitest assertion syntax but I just spent a frustrating hour trying to use MiniTest::Mock to get a controller destroy action to claim it failed so I could test the responder from Chapter 6 of Crafting Rails 4 Applications. So when I read that Thoughtbot uses shoulda + rspec, I decided to use rspec.

This blog post, Setting up the BDD stack on a new Rails 4 application, has some pretty good advise on how to set up the things I want to use. Remember to include ‘rspec-rails’ in both the test and development groups so generators will create rspec tests for things.

I regenerated the current pages model and added some not null constraints and default values. I like using FactoryGirl and have a number of utility methods I would like to transfer from my original codebase. I installed factory_girl_rails and then configured it as described in the Getting Started docs.