nathaniel bibler

Random thoughts, links, and code by Nathaniel Bibler

Google Friend Connect can’t handle my awesome.
Google Friend Connect can’t handle my awesome.
Mail can’t verify the identity of “imap.gmail.com”.
Mail can’t verify the identity of “imap.gmail.com”.
The view
The view
Sunday night Wynn from the monorail
Sunday night Wynn from the monorail
Extra virgin, first pressing from Spain
Extra virgin, first pressing from Spain
Mmm.. Brighthouse with RoadRunner Turbo
Mmm.. Brighthouse with RoadRunner Turbo

Ruby Gems with Autotest Discovery Break Rails

We’ll start off by clarifying which versions of which software I’m currently running:

I’m developing a basic Ruby on Rails application. Using Test::Unit and Shoulda for the test suite. The issue that I kept running into (sadly, for nearly a couple of hours) was this:

loading autotest/rails_rspec
Autotest style autotest/rails_rspec doesn't seem to exist. Aborting.

My application does not use Rspec, nor do any of the frozen gems or installed plugins. Here’s the kicker:

Simply installing a gem which has a custom autotest/discovery.rb will break you.

In this case, seed-fu, a gem which I was toying around with, contains such a file. Seed-fu was developed testing with Rspec (props for testing!). Simply installing that gem, not even requiring it or referencing it in any manor in my application, had ZenTest’s autotest pick up the rspec requirement and try to run with it. BAD AUTOTEST. NO. How did I fix it?

$ sudo gem uninstall mbleigh-seed-fu

Functional test for 404s in Rails 2.x

The Ruby on Rails version 2.x ActionController::TestCase thankfully abstracts a lot of the setup of your functional tests. There is a hidden issue, however, a problem that lingers for fully testing your controllers. How do you test for those automatically generated FAIL pages (i.e. 404, 500, 403, etc.)?

Hidden in the TestCase code, there is an answer. By default, all @request calls are made using a localhost-like IP, namely 0.0.0.0. TestCase overrides the rescue_action_without_handler and checks for that specific IP. If 0.0.0.0 is found, it will just forward the raised error to you, bypassing those pretty error pages. So, here’s the secret: Change your @request.remote_addr to anything other than ‘0.0.0.0’.

class MyController < ApplicationController
  def show
    raise ActiveRecord::RecordNotFound
  end
end


class MyControllerTest < ActionController::TestCase
  def test_show_rescues_with_404
    @request.remote_addr = '1.2.3.4'
    get :show, :id => 1
    assert_response :not_found # PASS!
  end
end
Also, be sure you remove any lines in your functional test that look similar to:
class MyController; def rescue_action(e) raise e end; end
Linux is the expert mode of operating systems. Nathaniel Bibler

Automated Phusion Passenger installation prior to 2.1.0

The following snippet will run the Phusion Passenger installation script (passenger-install-apache2-module) in an automated fashion. This would allow you to install the software via a boot script:
echo -en "\n\n\n\n" | passenger-install-apache2-module