How to set locale default_url_options for functional tests (Rails)

后端 未结 10 1738
予麋鹿
予麋鹿 2020-12-30 07:00

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={})
    {         


        
10条回答
  •  执笔经年
    2020-12-30 07:12

    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.

提交回复
热议问题