Ian White

The first WIN for us to come out of the Rails/Merb merge is that the awesome provides API in merb (which Dan gave a compelling introduction to at RailsCamp4), has made its way to rails-3 (along with some tweaks to the API).

This is a win for us because our response_for plugin provides similar functionality (for rails 2 apps). So that's one less plugin for me to maintain.

Can't wait for RARB!

Gorgeous Book Cover Designs

December 22nd, 2008

Ray Drainville

Why wait once a year for great book cover design? The Readerville Journal’s Most Coveted Covers goes all year round.

How the hell did I miss this site?!?

Ian White

I'm upgrading one of our apps to rails 2.2 and along with that, some plugin dependencies.

In this instance, I needed to monkey patch a method in attachment_fu to make it use the new i18n framework in Rails.

I got to thinking that it would be great if I could be reminded when this monkey patch is no longer necessary (ie. if I upgrade attachmnet_fu, and if it has made that method compatible with i18n). This was easily achieved, using rspec's pending.


pending: it's alive!

(you may want to skip straight to the pending monkey-patch stuff)

You may not know that it you pass a block to pending, it will still run that block, but it will expect it to fail. If the block passes, then rspec will tell you that the example is now working.

Here's an example: Nick is expanding on some specs for some code that I wrote.

it "fred@fang should not be a valid email" do
  @user.email = 'fred@fang'
  @user.should have(1).error_on(:email)
end

The above spec fails because currently, I don't have a complete email regexp. For whatever reason, I tell Nick that I'll look into that at some later point. What do we do next? We could open a ticket, or write a TODO, but what about that spec?

Using pending, we can add some live doco to our app:

it "fred@fang should not be a valid email" do
  pending "a better email regexp" do
    @user.email = 'fred@fang'
    @user.should have(1).error_on(:email)
  end
end

The above code will be shown as PENDING as long as the example fails. When someone gets around to writing a better regexp, the code will pass, and the rspec will fail the build telling you that the example is no longer pending.


Use pending to monitor your monkey-patches

So, we can use this neat feature of rspec to tell us when a monkey-patch is no longer required:

  • Write a spec that exhibits the desired behaviour
  • This spec should fail
  • Wrap the example(s) in pending block(s)
  • (optional, as your app specs might already test this) Write a spec that passes on the monkey-patched code.

In the example given above, all I had to do was spec out the behaviour that attachment_fu should exhibit, then wrap that in an informative pending block.

require File.dirname(__FILE__) + '/../spec_helper'

describe "attachment_fu and i18n" do
  describe "with an invalid attachment" do
    before do
      @model = mock('an attachment_fu model')
      @model.extend Technoweenie::AttachmentFu::InstanceMethods
      @model.stub!(:errors).and_return(mock('errors', :add => nil))
    
      # setup an invalid condition on the model
      @model.stub!(:attachment_options).and_return(:size => (2..3))
      @model.stub!(:size).and_return(1)
    end

    it "#attachment_attributes_valid? should not call default_error_messages" do
      pending "if this passes remove Asset#attachment_attributes_valid?" do
        ActiveRecord::Errors.should_not_receive(:default_error_messages)
        @model.send :attachment_attributes_valid?
      end
    end
  end
end

This means that if I upgrade to a version of attachment_fu that fixes the above problem, my specs will tell me my monkey-patch is no longer required.

Ray Drainville

In the past couple of months, two authors whom I admire have renewed interest in Dean Edwards’ confusingly-named IE7 script—a Javascript hack that makes Internet Explorer version 6 behave more like a standards-conscious browser.

The very title of Eric Meyer’s article—“Javascript will save us all”—suggest that we’re about to enter a golden age in support for the seven-year-old browser. And Jeremy Keith has recently advised people how to gauge when to use the IE7 script.

Well, I don’t know about you, but to me, this is more than music to my ears, it’s the equivalent of Bach being played on a glass harmonica right next to a chocolate fountain. But years of struggling with IE6 have hardened my defences. Since using Meyer’s CSS zero reset I’ve had great results with IE6—but only from the beginning of a site design I hasten to add. As I’ve written earlier the reset does little to fix a pre-existing design.

Dean’s script has popped up now & again over the years to tempt me again & again with its promises. But it’s nowhere near as well-known as you’d expect for something that gets such high praise from some very astute authors. Why is that?

Well, it might be because it doesn’t really do what you hope. It’s certainly nothing like a magic bullet. In fact, I’d recommend that you stay away from it. Why? Because you’ll have to go through the hard work of declaring a separate stylesheet for IE6 anyway: adding another script to the mix just adds more to the confusion of figuring out why something doesn’t work.

Both Edwards’ script and Keith’s recent article popped into my head because recently we’ve been working on the site of one of our favourite clients. In the course of making the site more amenable to search engine optimisation, it became clear that we should revisit the CSS of this, the last site we developed without the CSS reset.

The DD site as planned, in a standards-compliant browser

The DD site, as seen in IE6, based upon particularised CSS tweaks

The DD site, as seen in IE6 with Dean Edwards’ IE7 script

Now, it might seem like I’m cheating in the above examples: I removed the painstakingly-tweaked IE6 CSS when I introduced Edwards’s script. But I’m not. If I were to follow Meyer’s & Keith’s advice & used the IE7 script as a basis for my IE6-oriented work, I’d have a hell of a lot more tweaking to do, plus I’d have to cope with the rigmarole involved in dealing with someone else’s script.

So, take some advice: if something looks like it’ll magically solve all the problems that have consumed years of painful work, don’t bet your reputation, or your schedule on it.

Content Visualisation

December 9th, 2008

Ray Drainville

It’s kind of fun to visualise your use of words. The Wordle service will take text from your RSS feed(s) & make some nice visualisations for you:

Analysis of the “Falling Leaves” Blog

Analysis—supposedly—of the Argument from Design site

Looking at the generated images, all I can think is that they’re not actually analysing your site’s text, just randomly picking up words.

Best Book Cover Designs 2008

December 2nd, 2008

Ray Drainville

Book cover design means a lot to me. They say you’re not to judge one by its cover, but what do they know? A good book cover will attract your interest & help pick one out of thousands others. And as a visual essay on the title’s subject, the cover design can be a fantastic addendum to the book itself.

This year’s New York Times Best Book Cover Design covers some of the best examples of the year. My favourites:

Susan Faludi, “The Terror Dream”

Susan Faludi, “The Terror Dream”

J. Peter Scoblic, “US vs Them”

J. Peter Scoblic, “US vs Them”

Eric Wilson, “Against Happiness”

Eric Wilson, “Against Happiness”

Nathaniel Rich, “The Mayor’s Tongue”

Nathaniel Rich, “The Mayor’s Tongue”

Walter Benjamin, “The Work of Art in the Age of Mechanical Production”

Walter Benjamin, “The Work of Art in the Age of Mechanical Production”

refactorin' VC, 64 stylee

December 1st, 2008

Ian White

After railscamp#4, I went to #rorosyd's November meetup which experimented with 2 sessions of 6 lightning talk's, and was GREAT (but the lack of time for questions was not so great).

I gave one on refactoring VC (as in MVC) with response_for and inherit_views. For some reason, I had a serious bout of nostalgia as I was preparing the talk and came up with this (watch the for the 'bytes free' automatic countdown). If that pisses you off, then the slides will piss you off slightly less.

Liquid error: undefined method `current_page' for #