From 8898c30f55402a71fa4eb95f7633c8b014518440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 16:21:39 +0200 Subject: [PATCH] Rename AvailableLocales.available_locales method I'm not sure whether we should rename the class instead. I'm renaming the method because renaming the class would require more changes. --- app/models/remote_translation.rb | 2 +- lib/remote_translations/microsoft/available_locales.rb | 4 ++-- .../remote_translations/microsoft/available_locales_spec.rb | 4 ++-- spec/models/remote_translation_spec.rb | 6 +++--- spec/shared/system/remotely_translatable.rb | 2 +- spec/spec_helper.rb | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/remote_translation.rb b/app/models/remote_translation.rb index 1ef0f893d..10dd58a92 100644 --- a/app/models/remote_translation.rb +++ b/app/models/remote_translation.rb @@ -4,7 +4,7 @@ class RemoteTranslation < ApplicationRecord validates :remote_translatable_id, presence: true validates :remote_translatable_type, presence: true validates :locale, presence: true - validates :locale, inclusion: { in: ->(_) { RemoteTranslations::Microsoft::AvailableLocales.available_locales }} + validates :locale, inclusion: { in: ->(_) { RemoteTranslations::Microsoft::AvailableLocales.locales }} validate :already_translated_resource after_create :enqueue_remote_translation diff --git a/lib/remote_translations/microsoft/available_locales.rb b/lib/remote_translations/microsoft/available_locales.rb index 2bc39d2e3..6ddcc8f7a 100644 --- a/lib/remote_translations/microsoft/available_locales.rb +++ b/lib/remote_translations/microsoft/available_locales.rb @@ -4,7 +4,7 @@ require "cgi" require "json" class RemoteTranslations::Microsoft::AvailableLocales - def self.available_locales + def self.locales daily_cache("locales") do remote_available_locales.map { |locale| remote_locale_to_app_locale(locale) } end @@ -15,7 +15,7 @@ class RemoteTranslations::Microsoft::AvailableLocales end def self.include_locale?(locale) - available_locales.include?(locale.to_s) + locales.include?(locale.to_s) end private diff --git a/spec/lib/remote_translations/microsoft/available_locales_spec.rb b/spec/lib/remote_translations/microsoft/available_locales_spec.rb index 421ef606a..1e24a8fb4 100644 --- a/spec/lib/remote_translations/microsoft/available_locales_spec.rb +++ b/spec/lib/remote_translations/microsoft/available_locales_spec.rb @@ -1,12 +1,12 @@ require "rails_helper" describe RemoteTranslations::Microsoft::AvailableLocales do - describe ".available_locales" do + describe ".locales" do it "includes locales with the same format as I18n.available_locales" do allow(RemoteTranslations::Microsoft::AvailableLocales).to receive(:remote_available_locales) .and_return(%w[de en es fr pt zh-Hans]) - available_locales = RemoteTranslations::Microsoft::AvailableLocales.available_locales + available_locales = RemoteTranslations::Microsoft::AvailableLocales.locales expect(available_locales).to eq %w[de en es fr pt-BR zh-CN] end end diff --git a/spec/models/remote_translation_spec.rb b/spec/models/remote_translation_spec.rb index 8ce808ce5..c6ac6f6ad 100644 --- a/spec/models/remote_translation_spec.rb +++ b/spec/models/remote_translation_spec.rb @@ -39,18 +39,18 @@ describe RemoteTranslation, :remote_translations do it "checks available locales dynamically" do allow(RemoteTranslations::Microsoft::AvailableLocales) - .to receive(:available_locales).and_return(["en"]) + .to receive(:locales).and_return(["en"]) expect(remote_translation).not_to be_valid allow(RemoteTranslations::Microsoft::AvailableLocales) - .to receive(:available_locales).and_return(["es"]) + .to receive(:locales).and_return(["es"]) expect(remote_translation).to be_valid end it "is valid with a locale that uses a different name in the remote service" do - allow(RemoteTranslations::Microsoft::AvailableLocales).to receive(:available_locales).and_call_original + allow(RemoteTranslations::Microsoft::AvailableLocales).to receive(:locales).and_call_original allow(RemoteTranslations::Microsoft::AvailableLocales).to receive(:remote_available_locales) .and_return(["pt"]) diff --git a/spec/shared/system/remotely_translatable.rb b/spec/shared/system/remotely_translatable.rb index 870bf5147..2912b1497 100644 --- a/spec/shared/system/remotely_translatable.rb +++ b/spec/shared/system/remotely_translatable.rb @@ -11,7 +11,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume Setting["feature.remote_translations"] = true available_locales_response = %w[de en es fr pt zh-Hans] expect(RemoteTranslations::Microsoft::AvailableLocales) - .to receive(:available_locales).at_most(4).times + .to receive(:locales).at_most(4).times .and_return(available_locales_response) allow(Rails.application.secrets).to receive(:microsoft_api_key).and_return("123") end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index edd1036f2..f47bafa8d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -145,7 +145,7 @@ RSpec.configure do |config| config.before(:each, :remote_translations) do allow(RemoteTranslations::Microsoft::AvailableLocales) - .to receive(:available_locales).and_return(I18n.available_locales.map(&:to_s)) + .to receive(:locales).and_return(I18n.available_locales.map(&:to_s)) end config.around(:each, :with_frozen_time) do |example|