Let Globalize use I18n locale

This is a mistake I made in commit f2ef27d3. Back then I thought we
needed to keep Globalize.locale and I18n.locale in sync, but the truth
is it automatically happens when setting Globalize.locale to nil.

So now we can use I18n.with_locale (at least in the tests) and forget
about Globalize, which will make it easier to switch to Mobility in the
future.
This commit is contained in:
Javi Martín
2019-09-19 20:59:35 +02:00
parent a0ee0e661f
commit 41c99d9b27
8 changed files with 14 additions and 25 deletions

View File

@@ -824,11 +824,9 @@ describe "Admin budget investments" do
before do
I18n.with_locale(:es) do
Globalize.with_locale(:es) do
create(:budget_investment, title: "Proyecto de inversión", budget: budget)
end
end
end
scenario "Search investments by title" do
visit admin_budget_budget_investments_path(budget)

View File

@@ -3,7 +3,7 @@ require "rails_helper"
describe "Localization" do
scenario "Wrong locale" do
Globalize.with_locale(:es) do
I18n.with_locale(:es) do
create(:widget_card, title: "Bienvenido a CONSUL",
description: "Software libre para la participación ciudadana.",
link_text: "Más información",

View File

@@ -58,10 +58,10 @@ describe Budget::Group do
budget = create(:budget, name: "Teams")
charlie = create(:budget_group, budget: budget, name: "Charlie")
delta = create(:budget_group, budget: budget, name: "Delta")
zulu = Globalize.with_locale(:es) do
zulu = I18n.with_locale(:es) do
create(:budget_group, budget: budget, name: "Zulu", name_fr: "Alpha")
end
bravo = Globalize.with_locale(:es) do
bravo = I18n.with_locale(:es) do
create(:budget_group, budget: budget, name: "Bravo")
end

View File

@@ -555,11 +555,9 @@ describe Budget::Investment do
it "takes into consideration title fallbacks when there is no translation for current locale" do
create(:budget_investment, title: "BBBB")
Globalize.with_locale(:es) do
I18n.with_locale(:es) do
create(:budget_investment, title: "AAAA")
end
end
expect(Budget::Investment.sort_by_title.map(&:title)).to eq %w[AAAA BBBB]
end
@@ -570,13 +568,11 @@ describe Budget::Investment do
let!(:investment) do
I18n.with_locale(:es) do
Globalize.with_locale(:es) do
create(:budget_investment,
title_es: "Título del proyecto de inversión",
description_es: "Descripción del proyecto de inversión")
end
end
end
let(:all_investments) { Budget::Investment.all }

View File

@@ -54,9 +54,7 @@ RSpec.describe I18nContent, type: :model do
it "responds accordingly to the current locale" do
expect(i18n_content.value).to eq("Text in english")
Globalize.locale = :es
expect(i18n_content.value).to eq("Texto en español")
I18n.with_locale(:es) { expect(i18n_content.value).to eq("Texto en español") }
end
end

View File

@@ -402,10 +402,10 @@ describe Poll do
starts_at = Time.current + 1.day
poll1 = create(:poll, starts_at: starts_at, name: "Charlie")
poll2 = create(:poll, starts_at: starts_at, name: "Delta")
poll3 = Globalize.with_locale(:es) do
poll3 = I18n.with_locale(:es) do
create(:poll, starts_at: starts_at, name: "Zzz...", name_fr: "Aaaah!")
end
poll4 = Globalize.with_locale(:es) do
poll4 = I18n.with_locale(:es) do
create(:poll, starts_at: starts_at, name: "Bravo")
end

View File

@@ -32,10 +32,7 @@ RSpec.describe Poll::Question, type: :model do
end
context "locale with non-underscored name" do
before do
I18n.locale = :"pt-BR"
Globalize.locale = I18n.locale
end
before { I18n.locale = :"pt-BR" }
it "correctly creates a translation" do
poll_question.copy_attributes_from_proposal(proposal)

View File

@@ -44,7 +44,7 @@ RSpec.configure do |config|
config.before do |example|
DatabaseCleaner.strategy = :transaction
I18n.locale = :en
Globalize.locale = I18n.locale
Globalize.locale = nil
Globalize.set_fallbacks_to_all_available_locales
load Rails.root.join("db", "seeds.rb").to_s
Setting["feature.user.skip_verification"] = nil