Why is serving YUI3 over HTTPS so hard?

Yahoo! don’t have a HTTPS YUI3 endpoint. This means that you have to do some work to serve YUI3 if you want to avoid Internet Explorer users from getting warnings about mixed content (and you do). That work, for me at least, was particularly troublesome. However, I eventually found a simple method for solving the majority of the issues I was having.
Continue reading Why is serving YUI3 over HTTPS so hard?

Resolving Cucumber step ambiguities

Following the latest campaign against imperative Cucumber stories in favour of declarative stories (see especially Dan North’s great article on domain languages), I’ve been trying to get more naturalistic language into my stories. However, it becomes very easy to run into step ambiguities, something that Cucumber can try to handle on its own with --guess, but that I’d rather just resolve for it instead.
Continue reading Resolving Cucumber step ambiguities

Always define controller action methods in Rails 3

This morning was spent puzzling over a strange hard-to-reproduce Cucumber test failure in a project I have been upgrading from Rails 2.3.x to 3.0.3. It was only occurring after certain steps had been taken in previous Scenarios, and not when the failing Scenario was run on its own.

The solution was to explicitly define the controller action’s method in the controller. So the question to the world is: what changed, ActionController or something in the Cucumber chain?

ActiveRecord errors full_messages i18n incompatibility

If you’re running a Rails 2 app on a system with the latest i18n gem, ActiveRecord’s object.errors.full_messages spits out the string “{{attribute}} {{message}}”. You might notice that this is the old interpolation syntax for internationalisation in Rails 2. The latest i18n gem requires the %{} syntax. Sticking this into config/locales/en.yml fixed the problem for me, and future-proofs an app for when you accidentally upgrade the i18n gem on your production server:

Notes on a Rails 3 upgrade

Most scary output from console is warning rather than error.

RSpec 2 doesn’t have have_tag method. Now using webrat’s have_selector.

Plugin to help with upgrade only relevant to Rails 2 project, which seems silly.

Should use ‘extend ActiveModel::Naming’ in non-ActiveRecord classes used with view helpers that do record introspection e.g. form_for.

right_aws gem clobbers ActiveSupport 3, must use mikel fork

cucumber wasn’t following redirects. used this fork of webrat.

Builder needed requiring in application_helper, as I was using it to build markup.

Machinist 2 is a big change, but probably worth it. Cucumber needs database

Strange problem with matcher. I’d written matcher to allow ‘blah.should save’,
which clobbered ActiveRecord’s actual save method! Very specific, but worth
checking if you’re doing anything funky like that.

Routes were a breeze.

Array#sample rather than Array#rand

spec.opts now .rspec in Rails.root or ~/

Liking the enforced declarative style for validations.

email_spec had changed, features needed upgrading

#fullpath instead of #request_uri

Write more blog posts in shorthand!

Pong in HTML5 Canvas and YUI3, with tests!

In case you’re one of my clients, you might be wondering why I’ve been slacking off recently. Here’s why: I’ve been teaching myself ‘grown up’ JavaScript under instruction of Douglas Crockford (in book and video form, obviously). Crockford never mentions Test Driven Development, probably because he doesn’t do it. But I do, so I’ve been learning to do that in JavaScript too.

So here it is, HTML5 Canvas Pong.
Continue reading Pong in HTML5 Canvas and YUI3, with tests!

Setting 503 response code for Apache default virtual host

I know I promised my next post would be a tutorial on Chef, but this is kinda related. When new Rails servers are spinning up, I want Apache to respond to any requests with 503, both for SEO purposes in case I get my DNS wrong, and to tell load balancers that the node isn’t ready yet. It took me a while to grok the Apache docs to understand how to do this, as it is a bit counterintuitive (see the bit headed “‘redirect|R [=code]’ (force redirect)”). Please let me know if there’s a better way that perhaps doesn’t involve turning on RewriteEngine.
Continue reading Setting 503 response code for Apache default virtual host