kopongo.com

home

Globalize Functional Test Failing

29 Dec 2006

I added the globalize plugin to an application following some instructions on the web. There are quite a few sets of instructions out there, and nothing seems to be 'official'. Depending on what you use, you can run into difficulties.

My problem was with the functional tests. Running the tests, I get something like this:

 88) Error:
test_index(ServicesControllerTest):
ActionController::RoutingError: No url can be generated for the hash {:controller=>"services", :action=>"index"}
...
...   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/test_process.rb:336:in `get'
    ./test/functional/services_controller_test.rb:18:in `test_index'

The problem is that there is no default route that the tests seem to find. All of that code that the instructions told me to put into environment.rb does not seem to set any default locale. I knew that adding locales to the tests in the controllers would work, but I was not ready to start changing every

    get :index

to

    get :index, :locale => 'en'

in every controller test. Way too much work.

What seemed to work for me was to set up a default route. I changed this:

map.connect ':locale/:controller/:action/:id'  

to

map.connect ':locale/:controller/:action/:id', :defaults => { :locale => Globalize::Locale.language ? Globalize::Locale.language.code : 'en'}

and all was fine again.