Forum: Ruby on Rails Locale, routes, tests and default locale

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bob M. (Guest)
on 2008-11-20 10:29
Hi, I'm stuck in a maze :

routes.rb defines resources like this one
map.namespace(:admin) do |admin|
    admin.resources :sections, :path_prefix => '/:locale/admin'

Then, in functionnal test I have to (for example)
get :index, :locale => 'en'

I need to provide the :locale for every test I write and I find this too
much verbose for me. So I tried to write a base test controller that
would add the locale parameter to every request.

class BaseTestController < ActionController::TestCase
 def get method, options = {}
   get method, options.merge({:locale => 'en'})

Then, I define my test controller case like this

class Admin::SectionsControllerTest < BaseTestController
 def test_index
  get :index
  assert_response :success

Running the test I get error about get method beeing undefined in
BaseTestController. And don't understand why. There must be some
introspect mechanism used by Rails but how can I do ?

Any idea ?

BTW : the default_url_options method is useless here as it only works
with named routes and ignored by resources paths generator.
This topic is locked and can not be replied to.