From d317af572c596eb032efc816e7c0eef87055b632 Mon Sep 17 00:00:00 2001 From: Pierre Mesure Date: Fri, 24 May 2019 22:24:10 +0200 Subject: [PATCH 1/3] Set locales in test environment to avoid failed specs --- config/environments/test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/config/environments/test.rb b/config/environments/test.rb index 77cd9ed14..304339a8a 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,6 +1,18 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. + # Some tests require the following languages (en, es, fr, nl, pt-BR) + # so we override the available languages for the test environment. + config.i18n.default_locale = :en + available_locales = [ + "en", + "es", + "fr", + "nl", + "pt-BR" + ] + config.i18n.available_locales = available_locales + # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped From 7fc410678063a50445afb5a22f698c675b20fbc4 Mon Sep 17 00:00:00 2001 From: Pierre Mesure Date: Sun, 8 Sep 2019 19:52:47 +0200 Subject: [PATCH 2/3] Cleaning a few lines --- config/environments/test.rb | 9 +-------- spec/rails_helper.rb | 1 - 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 304339a8a..452f78fd7 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -4,14 +4,7 @@ Rails.application.configure do # Some tests require the following languages (en, es, fr, nl, pt-BR) # so we override the available languages for the test environment. config.i18n.default_locale = :en - available_locales = [ - "en", - "es", - "fr", - "nl", - "pt-BR" - ] - config.i18n.available_locales = available_locales + config.i18n.available_locales = %w[de en es fr nl pt-BR zh-CN] # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 4be75fc2b..4474759c1 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -13,7 +13,6 @@ require "capybara/rspec" require "selenium/webdriver" Rails.application.load_tasks if Rake::Task.tasks.empty? -I18n.default_locale = :en include Warden::Test::Helpers Warden.test_mode! From 7f8474ea955a1aba08273683b7ee4ba84a20f53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 9 Sep 2019 13:16:02 +0200 Subject: [PATCH 3/3] Reduce locales used in remote translations tests This way we can reduce the number of locales used in the test environment as well, while still testing every possible scenario for remote translations. --- spec/features/remote_translations_spec.rb | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/spec/features/remote_translations_spec.rb b/spec/features/remote_translations_spec.rb index 1ff98d9b2..92a16d1c3 100644 --- a/spec/features/remote_translations_spec.rb +++ b/spec/features/remote_translations_spec.rb @@ -5,8 +5,7 @@ describe "Remote Translations" do before do Setting["feature.remote_translations"] = true create(:proposal) - available_locales_response = ["ar", "de", "en", "es", "fa", "fr", "he", "it", "nl", "pl", - "pt", "sv", "zh-Hans", "zh-Hant"] + available_locales_response = %w[de en es fr pt zh-Hans] expect(RemoteTranslations::Microsoft::AvailableLocales).to receive(:available_locales). and_return(available_locales_response) end @@ -27,18 +26,14 @@ describe "Remote Translations" do end scenario "should display text in English" do - available_locales_with_fallback_en = [:ar, :de, :fa, :he, :nl, :pl, :sv] - - visit root_path(locale: available_locales_with_fallback_en.sample) + visit root_path(locale: :de) expect(page).to have_css ".remote-translations-button" expect(page).to have_content "The content of this page is not available in your language" end scenario "should display text in English after parse key" do - available_locales_with_fallback_en = [:"zh-CN", :"zh-TW"] - - visit root_path(locale: available_locales_with_fallback_en.sample) + visit root_path(locale: :"zh-CN") expect(page).to have_css ".remote-translations-button" expect(page).to have_content "The content of this page is not available in your language" @@ -53,9 +48,7 @@ describe "Remote Translations" do end scenario "with locale that has :es fallback" do - available_locales_with_fallback_es = [:es, :fr, :it] - - visit root_path(locale: available_locales_with_fallback_es.sample) + visit root_path(locale: :fr) expect(page).to have_css ".remote-translations-button" expect(page).to have_content "El contenido de esta página no está disponible en tu idioma" @@ -72,9 +65,7 @@ describe "Remote Translations" do end scenario "Not display remote translation button when locale is not included in microsoft translate client" do - not_available_locales = [:val, :gl, :sq] - - visit root_path(locale: not_available_locales.sample) + visit root_path(locale: :nl) expect(page).not_to have_css ".remote-translations-button" end