Week 4, Thursday

April 16, 2009 at 7:15 pm (Ruby, System Administration, Week 4) (, , , , )

Eric and I spent a good bit of time today trying to upgrade our app to Rails 2.3.2 (it’s currently 2.0.2), and we ran into several issues. One was that since we had Rails vendor’ed, our commit that upgraded the version caused our Subversion server some heartache on the commit side (but, strangely enough, not on the update side). Another was an error with the mysql gem that we solved on my machine and on another machine, but not on Eric’s machine, where we’ve been doing most of our work. Looong story short, we’ve reverted back to Rails 2.0.2 (which was a bit of a trial by itself), and next time we’ll most likely use Git and start right out using 2.3 (or higher!). <sarcasm>You have got to love debugging.</sarcasm>

I took a story, mostly alone, this afternoon and got it into a pretty good state, and meanwhile Eric worked on setting up a continuous integration server. I set up the exception_notification plugin and configured it for our project, which was pretty simple since I’d done it before. I just had to spend a bit of time figuring out how to get it under test (not the plugin itself, since that’s well-tested already: my implementation of it). I ended up getting some unit tests on the controller that I think are sufficient, but I don’t know how to get Cucumber cooperating yet for integration tests, so those are missing for now.

In case anyone else is struggling with how to write specs that test emails being sent when someone hits a bad url (like “/asgiuaguw”) in your application, here’s what I did (in a before block):


ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
controller.use_rails_error_handling!

The first three lines just set up a fake mailing environment that you can query later with things like:

ActionMailer::Base.deliveries[0].to.should include("colin@8thlight.com")

Where ActionMailer::Base.deliveries[0] is a TMail::Mail object with all the information I can imagine you’d need to know about an email you’re sending.

The last line (controller.use_rails_error_handling!) ensures that RSpec isn’t going to rescue the exception for you (usually if there’s an exception during a test, the test fails with an error), and instead allows Rails to handle exceptions as it would during normal processing (with a rescue_action_in_public, for instance, as exception_notification uses). That way we can test that the behavior we want actually happens!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: