From f2ef27d3ae47eab985064200e6c4365142d808a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Mart=C3=ADn?= Date: Mon, 2 Jul 2018 23:12:41 +0200 Subject: [PATCH] Always set `Globalize.locale` after `I18n.locale`. The test "Budget Investments Show milestones" was failing in certain cases where `Globalize.locale` had been changed in a previous test. Since having different values in `Globalize.locale` and `I18n.locale` has proven to be an issue on the test enviroment, this commit also changes application code in order to avoid similar situations on production. See issue #2718. --- app/controllers/application_controller.rb | 1 + app/controllers/concerns/translatable.rb | 5 ----- app/controllers/management/base_controller.rb | 1 + spec/spec_helper.rb | 1 + 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2e9b13462..e97b87cd3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -59,6 +59,7 @@ class ApplicationController < ActionController::Base end I18n.locale = locale + Globalize.locale = I18n.locale end def set_layout diff --git a/app/controllers/concerns/translatable.rb b/app/controllers/concerns/translatable.rb index 4b4b14d87..5c3b1be62 100644 --- a/app/controllers/concerns/translatable.rb +++ b/app/controllers/concerns/translatable.rb @@ -2,7 +2,6 @@ module Translatable extend ActiveSupport::Concern included do - before_action :set_translation_locale before_action :delete_translations, only: [:update] end @@ -12,10 +11,6 @@ module Translatable resource_model.globalize_attribute_names.select { |k, v| params.include?(k.to_sym) && params[k].present? } end - def set_translation_locale - Globalize.locale = I18n.locale - end - def delete_translations locales = resource_model.globalize_locales. select { |k, v| params[:delete_translations].include?(k.to_sym) && params[:delete_translations][k] == "1" } diff --git a/app/controllers/management/base_controller.rb b/app/controllers/management/base_controller.rb index be6dd66c0..bcebfebaa 100644 --- a/app/controllers/management/base_controller.rb +++ b/app/controllers/management/base_controller.rb @@ -39,6 +39,7 @@ class Management::BaseController < ActionController::Base session[:locale] ||= I18n.default_locale I18n.locale = session[:locale] + Globalize.locale = I18n.locale end def current_budget diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2598f085e..47212d343 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -41,6 +41,7 @@ RSpec.configure do |config| config.before do |example| DatabaseCleaner.strategy = :transaction I18n.locale = :en + Globalize.locale = I18n.locale load Rails.root.join('db', 'seeds.rb').to_s Setting["feature.user.skip_verification"] = nil end