Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Monthly Archives: January 2008

Joe Moore

Standup 01/04/2007

Joe Moore
Friday, January 4, 2008

Interesting Things

  • IE Fun: when building a DOM tree by hand (such as in Javascript), don’t forget to add <tbody> tags in your tables! These are required in Internet Explorer 6 and 7. The tables will not appear without them.
  • Pivot Erik wrote a post about firing mouse events in tests using Yahoo’s YUI Javascript library. Check it out!
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Helpful Named-Route Error Messages

Pivotal Labs
Friday, January 4, 2008

Sometimes I call a named route incorrectly: edit_user_project_path(project). And I get an illegible error message:

user_project_url failed to generate from {:action=>"show", :user_id=>#<Project id: 1, name: "Andy falls off a cliff", created_at: "2007-12-03 15:15:08", creator_id: 2, completed_at: nil, description: "", deleted_at: nil>, :controller=>"projects"}, expected: {:action=>"show", :controller=>"projects"}, diff: {:user_id=>#<Project id: 1, name: "Andy falls off a cliff", created_at: "2007-12-03 15:15:08", creator_id: 2, completed_at: nil, description: "", deleted_at: nil>}

I can’t read that. This, however, is much clearer:

user_project_url failed to generate from {:action=>"show", :user_id=>"1", :controller=>"projects"}, expected: {:action=>"show", :controller=>"projects"}, diff: {:user_id=>"1"}

The error message really ought to call #to_param on the path parts, don’t you think?

class ActionController::Routing::RouteSet
  # try to give a helpful error message when named route generation fails
  def raise_named_route_error(options, named_route, named_route_name)
    helpful_options = options.inject({}) {|hash, (key, value)| hash.merge(key => value.to_param) }
    diff = named_route.requirements.diff(options)
    unless diff.empty?
      raise RoutingError, "#{named_route_name}_url failed to generate  from #{helpful_options.inspect}, expected:  #{named_route.requirements.inspect}, diff:  #{named_route.requirements.diff(helpful_options).inspect}"
    else
      required_segments = named_route.segments.select {|seg| (!seg.optional?) && (!seg.is_a?(DividerSegment)) }
      required_keys_or_values = required_segments.map { |seg| seg.key rescue seg.value } # we want either the key or the value from the segment
      raise RoutingError, "#{named_route_name}_url failed to generate from #{helpful_options.inspect} - you may have ambiguous routes, or you may need to supply additional parameters for this route.  content_url has the following required parameters: #{required_keys_or_values.inspect} - are they all satisfied?"
    end
  end
end

Make it so!

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

alias_method_chain :validates_associated, :informative_error_message

Pivotal Labs
Friday, January 4, 2008

I dislike the vague error message produced by validates_associated.

class User
  validates_associated :profile
  delegate ..., :to => :profile
end

I see the following error message: profile is invalid. But WHY was the profile invalid? The validation errors from the profile should bubble up to the user. So,

module ActiveRecord::Validations::ClassMethods
  def validates_associated(association, options = {})
    class_eval do
      validates_each(association) do |record, associate_name, value|
        associate = record.send(associate_name)
        if associate && !associate.valid?
          associate.errors.each do |key, value|
            record.errors.add(key, value)
          end
        end
      end
    end
  end
end

Now we see:

Music tastes can't be blank

Eh, voila!

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Parker Thompson

Kombucha anyone?

Parker Thompson
Friday, January 4, 2008

As geeks we like science experiments. As San Franciscans (mostly) we like anything novel, particularly if it’s organic, healthy, and foreign. So, a few months ago, after realizing our employer couldn’t afford our kombucha (fermented green or black tea) habit, we started brewing our own:

Kombucha

Now we’ve got more “mushrooms” (actually a bacteria and yeast symbiote called a scoby). These are the “strata” in the jars above. So, if ever you’ve ever wanted to make your own kombucha (it’s easy and tasty) , or if you’ve never heard of it and the idea of a beverage somewhere between ice tea, lemonade, and beer sounds tasty, come by or paypal me postage and I’ll give you a scoby.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Joe Moore

Standup 01/03/2007

Joe Moore
Thursday, January 3, 2008

Interesting Things

  • As a follow-up to yesterday’s “As for Help” regarding geo-spatial algorithms, one developer implemented MySQL’s geo-spatial code with great success. One caveat: the table must be an MyISAM rather than InnoDB in order to get the indexes, and thus speed benefits. Wes suggested this helpful link.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Joe Moore

Standup 01/02/2008

Joe Moore
Wednesday, January 2, 2008

Interesting Things

  • Rails tweaking: test startup times can be very slow due to Fixture loading, especially for HABTM. We monkey-patched the Fixture-loading code that handles HABTM, resulting in a test suite performance increase of 300% for one project! We’ll submit the patch to Rails core and keep you posted.

Ask for Help

  • “Does anyone know an efficient algorithm for detecting overlapping rectangles made of up latitudes/longitudes… in SQL?”
    Or, in other words, detecting if two selections on a map overlap. The latitudes and longitudes are stored in a MySQL database. MySQL has some GIS features that we’ll explore.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

CPU Leak

Alex Chaffee
Wednesday, January 2, 2008

I just had to quit Firefox for the umpteenth time because it was taking up 25% of my CPU and 1.5 GB of virtual memory. It makes my lap hot and burns down my battery and activates my fan and slows down my click response time. I have no idea if it was Gmail or Google Reader or one of the other JS-heavy apps and frankly, I’m sick of guessing.

Let’s face it: the browser is an operating system. It’s time it started acting like one.

Here’s what I want my next browser to do:

  • Put every tab’s JS in its own thread or process space
  • Pause that process when I switch tabs (i.e. I don’t want Gmail to check for incoming mail or chats unless it’s in a visible tab)
  • Show me a list of the CPU and memory usage of each JS slice like “top” or the Windows process monitor and allow me to kill them without restarting my browser
  • Same goes for Flash but even moreso: I want every seizure-inducing, focus-stealing, ringtone-blaring flash app to be individually killable and blockable
  • Show me the content of the page now even if some stupid ad or web bug or analytics script on a different server is slow to load

And for Santa’s sake when I tell you to quit don’t swap in every little JS object and free it individually. Throw the whole heap away and quit, damn your eyes!

OK? OK.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Firing mouse events in tests

Pivotal Labs
Wednesday, January 2, 2008

The Bad News

Sending mouse events such as click and mouseover in JsUnit tests can be really hard.

More Bad News

Prototype doesn’t make it any easier. Sam Stephenson says:

We would very much like to support it in the future. It’s fairly
complicated to implement native event firing across all supported
browsers, so in 1.6.0, fire works with custom events only.

YUI To The Rescue

YAHOO.util.UserActions can simulate some user actions. Unfortunately, calls to YUI can look a bit clunky in a Prototype-heavy codebase:

var element = new Element("div").insert("Hi");
var offset = element.cumulativeOffset();
YAHOO.util.UserAction.click(element, { shiftKey: true });

YUI + Prototype FTW

A little mixin magic:

Element.addMethods({
  simulateClick: YAHOO.util.UserAction.click.bind(YAHOO.util.UserAction),
  simulateDblClick: YAHOO.util.UserAction.dblclick.bind(YAHOO.util.UserAction),
  simulateMousedown: YAHOO.util.UserAction.mousedown.bind(YAHOO.util.UserAction),
  simulateMouseup: YAHOO.util.UserAction.mouseup.bind(YAHOO.util.UserAction),
  simulateMouseover: YAHOO.util.UserAction.mouseover.bind(YAHOO.util.UserAction),
  simulateMouseout: YAHOO.util.UserAction.mouseout.bind(YAHOO.util.UserAction),
  simulateMousemove: YAHOO.util.UserAction.mousemove.bind(YAHOO.util.UserAction)
});

and now our test code looks nicer:

var element = new Element("div").insert("Hi");
var offset = element.cumulativeOffset();
myElement.simulateClick({ shiftKey: true });
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (778)
  • rails (113)
  • testing (87)
  • ruby (83)
  • ruby on rails (70)
  • jobs (62)
  • javascript (54)
  • techtalk (44)
  • rspec (38)
  • activerecord (29)
  • productivity (29)
  • gogaruco (29)
  • ironblogger (29)
  • git (28)
  • nyc (27)
  • rubymine (25)
  • bloggerdome (22)
  • mobile (22)
  • cucumber (20)
  • process (19)
  • pivotal tracker (19)
  • jasmine (19)
  • design (18)
  • ios (18)
  • webos (17)
  • objective-c (17)
  • android (16)
  • palm (16)
  • "soft" ware (16)
  • fun (15)
  • tracker ecosystem (15)
  • ci (15)
  • cedar (15)
  • rails3 (14)
  • performance (14)
  • bdd (14)
  • gem (13)
  • tdd (13)
  • selenium (12)
  • css (12)
  • goruco (12)
  • bundler (12)
  • meetup (11)
  • railsconf (11)
  • nyc-standup (11)
  • capybara (10)
  • mac (10)
  • mojo (10)
  • chef (10)
  • api (10)
Subscribe to Community Feed
  1. ←
  2. 1
  3. 2
  4. 3
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >