Erik Hanson's blog



Erik HansonErik Hanson
Standup 2009-11-06
edit Posted by Erik Hanson on Friday November 06, 2009 at 01:38PM

Ask for Help

Exceptions thrown in Rails views get wrapped by ActionView::TemplateError which makes rescuing specific exceptions hard

It's probably best to prepare all your data in your controller or models and not in the view, which will obviate this and other problems.

Ask for Help

Does anyone have suggestions for an off-the-shelf data reporting tool to help display some data in a webapp for internal users to see?

form.submit() vs. <form onsubmit="...">: An onsubmit attribute added to a form element doesn't get called when form.submit() is called from Javascript.

  • Try using Javascript to attach an onsubmit handler rather than adding it as an attribute of the form element.
  • Instead of calling form.submit() from Javascript, send a click event to a hidden submit button.

Timezones are being ignored when a date is passed into ActiveRecord's find method, but are not ignored when passed into other methods.

This seems to be due to a bug in ActiveSupport's to_s(:db). One solution is to override to_s and fix the time zone.

Interesting Things

  • When trying to create an ssh tunnel to EngineYard, set GatewayPorts to yes in sshd, otherwise the tunnel won't bind to your local computer.

  • WAVE Toolbar (Web accessiblity evaluation tool) is a great Firefox extension that shows you which parts of your pages have accessibility issues.

  • The next meeting of the San Francisco Pivotal Tracker Users Group is tonight at 6:30 PM at the Pivotal Labs headquaters on Market St.

Erik HansonErik Hanson
Standup 2009-11-02: WTF?
edit Posted by Erik Hanson on Tuesday November 03, 2009 at 08:55AM

Interesting Things

  • git-wtf is a useful script for showing the state of your git repo. It was mentioned specifically for its ability to show you the details about the commits you haven't yet pushed (especially if there have been multiple commits by other people in the meantime).

Erik HansonErik Hanson
Standup 2009-02-26
edit Posted by Erik Hanson on Thursday February 26, 2009 at 10:00PM

Interesting Things

  • Shotgun is an automatic reloading version of the rackup command that's shipped with Rack.

Erik HansonErik Hanson
Standup 2009-02-25
edit Posted by Erik Hanson on Thursday February 26, 2009 at 09:46PM

Interesting Things

  • The Golden Gate Ruby Conference is now accepting proposals for talks.

  • Rails by default stores its session in a browser cookie as an encrypted string. If you want to get the contents of that cookie from within Rails, you can call "session.dbman.send :marshal, session.data". If you want to get that value from tests, you'll have to use an integration test, as functional tests mock out too much of the session store.

Erik HansonErik Hanson
Pattern for Functional Testing
edit Posted by Erik Hanson on Friday November 14, 2008 at 05:40PM

Regular Selenium tests (in Java) might look like:

selenium.open("/login");
selenium.type("id=username", "bob");
selenium.type("id=password", "password");
selenium.click("Login");
selenium.waitForPageToLoad();
selenium.click("My Account");
selenium.waitForPageToLoad();
assertEquals("bob", selenium.getText("//table[2]/tr[3]/td[2]/");

After a few tests, this kind of thing becomes painful to manage. The typical solution is to create a bunch of constants for IDs and Xpaths, but that doesn't help too much.

Fellow Pivot Mike Grafton came up with a cool pattern for improving on this. The idea is to create a class representing each page of your web app. Each class contains two types of methods: a bunch of action methods (clickMyAccountLink(), typeUsername()), and a bunch of inspection commands (isLoginButtonEnabled(), getLoggedInUsername()).

When an action takes you to a new page, the corresponding action method returns a new class representing that page. When it stays on the same page, the method just returns "this". This allows methods to be chained to make the tests more readable.

Here's how that test would look using this new pattern:

MyAccountPage myAccountPage = new LoginPage(selenium)
  .typeUsername("bob")
  .typePassword("password")
  .clickLoginButton()
  .clickMyAccountLink();

assertEquals("bob", myAccountPage.getLoggedInUsername());

The constructor of each page class should validate that it's on the correct page (waiting if necessary, and perhaps asserting on the page title).

Erik HansonErik Hanson
Standup May 2, 2008
edit Posted by Erik Hanson on Friday May 02, 2008 at 04:35PM

Ask for Help

  • "Can anyone recommend a tool to help find cross-site scripting (XSS) vulnerabilities?" One suggestion was Wikto.

Erik HansonErik Hanson
Standup May 1, 2008
edit Posted by Erik Hanson on Thursday May 01, 2008 at 04:15PM

Interesting Things

Ask for Help

  • "Is it really safe to set allow_concurrency in ActiveRecord if it's going to be called from a script and not from Rails or Mongrel?"

Erik HansonErik Hanson
Standup April 28, 2008
edit Posted by Erik Hanson on Tuesday April 29, 2008 at 03:34AM

Interesting Things

  • Tip: acts_as_solr will revert to using Rexml if it can't find the much faster libxml-ruby. So if your solr processes start to take forever, make sure libxml-ruby is being used.

Erik HansonErik Hanson
Standup April 25, 2008
edit Posted by Erik Hanson on Friday April 25, 2008 at 04:18PM

Interesting Things

  • Erector is nearing its initial beta release.

    Erector is a Builder-like view framework, inspired by Markaby but overcoming some of its flaws. In Erector all views are objects, not template files, which allows the full power of object-oriented programming (inheritance, modular decomposition, encapsulation) in views.

  • The latest Rails Podcast features Pivotal's Nathan Sobo talking about Treetop.

    Treetop is a language for describing languages. Combining the elegance of Ruby with cutting-edge parsing expression grammars, it helps you analyze syntax with revolutionarily ease.

Ask for Help

  • "Can anyone suggest any solutions, or point to a web site that seems to have solved the following problem: an iframe that's showing content from one domain wants to communicate with its parent document that's showing content from another domain, without modifying the parent document's URL or refreshing the parent document's page? Adding Javascript to the parent document is okay, but installing a proxy on the server of the parent document's domain isn't possible."

Other articles: