How to set locale default_url_options for functional tests (Rails)

后端 未结 10 1761
予麋鹿
予麋鹿 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条回答
  •  猫巷女王i
    2020-12-30 07:32

    Things changed again with Ruby 5.1. Here's what worked for me:

    class ActionController::TestCase
      module Behavior
        module LocaleParameter
          def process(action, params: {}, **args)
            # Locale parameter must be a string
            params[:locale] = I18n.locale.to_s
            super(action, params: params, **args)
          end
        end
      end
      prepend Behavior::LocaleParameter
    end
    

提交回复
热议问题