How to set locale default_url_options for functional tests (Rails)
For Rails 5, I found this simple solution
In test_helper.rb
based on action_dispatch/testing/integration.rb
module ActionDispatch::Integration
class Session
def default_url_options
{ locale: I18n.locale }
end
end
end
In the Rails 3.1-stable branch, the process method is now within a Behavior
module. So here is the code which worked for me (slightly different from John Duff's answer):
class ActionController::TestCase
module Behavior
def process_with_default_locale(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
parameters = { :locale => I18n.default_locale }.merge( parameters || {} )
process_without_default_locale(action, parameters, session, flash, http_method)
end
alias_method_chain :process, :default_locale
end
end
And I made sure this code gets called before running the specs/tests. A good place to put it is in the test_helper class.