Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

Standup 08/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, or probably better, don’t create methods called “target”.
  • Since 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

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.

  1. Thanks for that 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:



  2. Joseph Palermo says:

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

  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’

    This seems to work.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *