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

Standup 08/11/2008

Joseph Palermo
Monday, August 11, 2008

Interesting Things

  • If you have a “target” method on your model, things will get a bit weird when you try to access this method through an association. Since associations have their own “target” method, you actually need to call assocation.target.target, or probably better, don’t create methods called “target”.
  • Since Time.now always returns the time for the local timezone, if you use it in your fixtures, but then have your app running under a different time zone, the times in your fixtures will be incorrect. Use the active support helpers such as 0.days.ago instead, or if you have a timezone configured in your environment, you can use Time.zone.now

Ask for Help

“How can I test the route helpers in RSpec? If I’m passing a complex set of options to a helper I’d like to test that it’s giving me what I expect.”

Nobody had any serious suggestions, although many humorous testing scenarios were mentioned.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

3 Comments

  1. Hendrik Volkmer says:

    Thanks for that target.target hint. We discovered the same strange behaviour but haven’t tracked it down yet. The target method was introduced in Rails 2.0 wasn’t it?

    I thought that was worth a small thank you post on our blog: http://devblog.imedo.de/2008/8/11/stay-on-target

    :)

    Cheers,
    Hendrik

    August 11, 2008 at 5:44 pm

  2. Joseph Palermo says:

    Glad it was helpful, [Josh](http://blog.hasmanythrough.com/) mentioned at standup this morning that proxy_target is an alias of target on the proxy. So you can use association.proxy_target.target which might be a bit more clear in your code.

    August 12, 2008 at 6:15 pm

  3. Davis W. Frank says:

    As for testing route helpers in RSpec, I found that this will work.

    You’re testing this in a Helper, so pick one. Say, `application_helper_spec.rb`.

    In your example, open up the helper and make the route helper you want to test public, then make an expectation as normal:

    describe Foo do
    it ‘should make the URL I want’ do
    class < < helper
    public(:custom_path)
    end

    helper.custom_path(:thing => ‘foo’).should == ‘/foo’
    end
    end

    This seems to work.

    August 12, 2008 at 8:13 pm

Add New Comment Cancel reply

Your email address will not be published.

Joseph Palermo

Joseph Palermo
San Francisco

Recent Posts

  • Why Pivots don’t do their best work at night
  • [Standup][SF] 08/28/12: They at least strongly dislike each other
  • 06/26/12: Headless is fine, double headless is trouble
Subscribe to Joseph's Feed

Author Topics

agile (18)
named_scope (1)
ruby on rails (2)
bug (1)
performance (1)
  • 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 >