Head London

SVN Branching/tagging and Redmine integration

Thursday 6th November 2008

Here at Head, we use Redmine for our issue-tracking and collaboration needs, and it’s truly great. We’ve now replaced Trac, which was also really good, but we’re finding that the multiple-projects support in Redmine really trumps the single-project-per-installation model of Trac.

The only problem we’ve run into so far with Redmine was a problem setting up SVN branches when using Redmine.pm, the Perl authentication module.  Any attempt to branch a repo resulted in an Apache segfault and an explosion on the client-side.  The relatively simple solution was to replace the apache2-mpm-worker module with the apache2-mpm-prefork module.  I found this solution tucked away in the Redmine forums, but I figured I’d better make a note of it as the solution was a bit hard to find.

Getting on Rails Quickly for Debian-based systems

Monday 3rd November 2008

Just to speed things up for anybody who needs it, here are the commands we use to get Rails sites working on a fresh Debian-based system.

sudo apt-get install ruby rdoc1.8 ri1.8 irb1.8 irb ruby1.8-dev build-essential mysql-server libmysql-ruby libmysqlclient15off libmysqlclient15-dev mysql-admin imagemagick librmagick-ruby libmagick9-dev libopenssl-ruby subversion git-core

Next, go to http://rubyforge.org/frs/?group_id=126 and download the latest rubygems package (grab the .tar.gz file).

Extract it, and run

sudo ruby setup.rb

When that finishes, you should be able to type

gem -v

And get a version number (like 1.3.1 at present).  If this doesn’t work, it may be the case that it installed as command “gem1.8″ (rather than “gem”).  So we can fix this pretty easily:

[code]sudo ln -s /usr/bin/gem1.8 /usr/bin/gem[/code]

Lastly you can install all the commonly used gems we use here:

[code]gem sources -a http://gems.github.com
sudo gem install mongrel ruby-debug mysql mislav-will_paginate ferret
acts_as_ferret rmagick fastercsv rails capistrano rake[/code]

Installing Phusion Passenger on Centos With a Custom Apache2

Monday 21st July 2008

We’re currently running Apache2 on an old (and very stable) version of CentOS. It’s so ancient it didn’t come with Apache 2, so we’ve got it installed from source. Today we’re making the big move to running our Rails apps on Phusion Passenger (a.k.a mod_rails), but we ran into some problems with the compilation of the Apache module, mainly because passenger-install-apache2-module couldn’t figure out where any of the Apache development headers were. It’s a great installer but it can’t magically figure out where Apache’s keeping its development headers.

The solution was pretty simple, extracted from here and boiled down, it’s:

[code]export APXS2=/usr/local/apache/bin/apxs
export APR_CONFIG=/usr/local/apache/bin/apr-1-config[/code]

You may need to change the path depending on where you’ve got Apache installed.

Got Gimme?

Friday 14th March 2008

Gimme Moo Cards 19

A 50p McDonald’s gift certificate, an air freshener, driftwood with google eyes glued onto it , anything from Lush… we’ve all received the occasional ‘less than satisfactory’ gift, but not anymore. Now you can let your family and friends know exactly what you want and where to find it online.
Head Labs had just released Gimme – a new Facebook application that lets you make product lists and keeps you clued-up on the latest trends.More than a wish-list, Gimme acts as your own product storage list of all the stuff you want online, you can add and edit any product found through our integrated search or found by you on your internet travels with our customised bookmarklet.

  • An integrated search – find what you want easily by searching thousands of online retailers all within Facebook.
  • Price comparison engine – buy your friends what they want at the best price.
  • Editor’s Picks – our dedicated team of shopping aficionados scour the net looking for intriguing products you might like.
  • What’s Popular on Facebook – it’s what everyone else likes the most.
  • Themes – customise your list by adding a graduation, birthday, wedding list, or just a funky looking theme.
  • Steal stuff off your friends – perfect for the lazy shopper, just add items from your friends list without all that thinking.
  • Birthday alerts – lets you know when your friends’ birthdays are coming up and what they want.

Find out what all the hoopla is about at the apps page over on facebook.

Testing Single Table Inheritance Models in Ruby on Rails

Thursday 24th May 2007

I had a small problem today when trying to do unit testing of single-table inheritance models in Rails, all my tests initially failed and I wasn’t quite sure why. It’s a pretty simple fix but isn’t documented too well anywhere, so here’s the skinny.

My model structure was pretty simple, I had a Content class that acted as a base class for Article, Page, Event, and a bunch of others. So I added a Content class using a model generator, ending up with:

[code]
class Content < ActiveRecord::Base
end
[/code]

Then I added Article and Page classes using the model generator, and changed the default class definitions so that each of those classes inherited from Content. That looks like this:

[code]
class Article < Content
end

class Page < Content
end
[/code]

Then I ran my tests, expecting that the default “test_true” assertions were going to pass. Explosion!

The first problem was that I named my table “content”, not “contents”. Since this isn’t included in the pluralization rules for Rails, my model was trying to find a table called “contents”. This was easily fixed by changing the Content class like this:

[code]
class Content < ActiveRecord::Base
set_table_name "content"
end
[/code]

However, tests were still failing. After quite a bit of googling, it turns out that it was the auto-generated test fixture names that were the problem. First off, the articles.yml and pages.yml file were useless – when testing STI classes, you set up your fixtures in the superclass fixture definition. That is, in my case I only needed content.yml, and if I wanted to set up an Article fixture in there, it would look like this:

[code]
article_one:
id: 1
title: foo
body: this is a body
type: Article
[/code]

Note that I had to set the type property manually to the class name of the subclass object that the fixture is for. Note also the name of the fixtures file – because of my use of a table name for Content that’s not in the default pluralization rules, the fixture file needed to be content.yml rather than the default contents.yml.

One more thing and it all fell into place. All of the generated unit tests had incorrect fixture file names in them – content_test.rb had fixtures :contents, article_test.rb had fixtures :articles, and page_test.rb had fixtures :pages. All of these needed to be changed to fixtures :content before any of the tests would work. Rails apparently looks for a database table name matching the name of the fixtures file, so until I did this my tests were failing when looking for nonexistent tables.

Hopefully that will save someone from the horror of having to trawl the web using the keywords rails sti test.