How to set locale default_url_options for functional tests (Rails)

Posted by insane.dreamer on Stack Overflow See other posts from Stack Overflow or by insane.dreamer
Published on 2009-12-31T22:38:14Z Indexed on 2010/04/02 6:23 UTC
Read the original article Hit count: 518

Filed under:
|
|

In my application_controller, I have the following set to include the locale with all paths generated by url_for:

  def default_url_options(options={})
    { :locale => I18n.locale }
  end

My resource routes then have a :path_prefix = "/:locale"

Works fine on the site.

But when it comes to my functional tests, the :locale is not passed with the generated urls, and therefore they all fail. I can get around it by adding the locale to the url in my tests, like so:

  get :new, :locale => 'en'

But I don't want to have to manually add the locale to every functional test.

I tried adding the default_url_options def above to test_helper, but it seems to have no effect.

Is there any way I can change the default_url_options to include the locale for all my tests?

Thanks.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about testing