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.
This commit is contained in:
Javi Martín
2023-07-19 16:21:39 +02:00
parent 36c3ba6601
commit 8898c30f55
6 changed files with 10 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ class RemoteTranslation < ApplicationRecord
validates :remote_translatable_id, presence: true validates :remote_translatable_id, presence: true
validates :remote_translatable_type, presence: true validates :remote_translatable_type, presence: true
validates :locale, 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 validate :already_translated_resource
after_create :enqueue_remote_translation after_create :enqueue_remote_translation

View File

@@ -4,7 +4,7 @@ require "cgi"
require "json" require "json"
class RemoteTranslations::Microsoft::AvailableLocales class RemoteTranslations::Microsoft::AvailableLocales
def self.available_locales def self.locales
daily_cache("locales") do daily_cache("locales") do
remote_available_locales.map { |locale| remote_locale_to_app_locale(locale) } remote_available_locales.map { |locale| remote_locale_to_app_locale(locale) }
end end
@@ -15,7 +15,7 @@ class RemoteTranslations::Microsoft::AvailableLocales
end end
def self.include_locale?(locale) def self.include_locale?(locale)
available_locales.include?(locale.to_s) locales.include?(locale.to_s)
end end
private private

View File

@@ -1,12 +1,12 @@
require "rails_helper" require "rails_helper"
describe RemoteTranslations::Microsoft::AvailableLocales do describe RemoteTranslations::Microsoft::AvailableLocales do
describe ".available_locales" do describe ".locales" do
it "includes locales with the same format as I18n.available_locales" do it "includes locales with the same format as I18n.available_locales" do
allow(RemoteTranslations::Microsoft::AvailableLocales).to receive(:remote_available_locales) allow(RemoteTranslations::Microsoft::AvailableLocales).to receive(:remote_available_locales)
.and_return(%w[de en es fr pt zh-Hans]) .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] expect(available_locales).to eq %w[de en es fr pt-BR zh-CN]
end end
end end

View File

@@ -39,18 +39,18 @@ describe RemoteTranslation, :remote_translations do
it "checks available locales dynamically" do it "checks available locales dynamically" do
allow(RemoteTranslations::Microsoft::AvailableLocales) allow(RemoteTranslations::Microsoft::AvailableLocales)
.to receive(:available_locales).and_return(["en"]) .to receive(:locales).and_return(["en"])
expect(remote_translation).not_to be_valid expect(remote_translation).not_to be_valid
allow(RemoteTranslations::Microsoft::AvailableLocales) allow(RemoteTranslations::Microsoft::AvailableLocales)
.to receive(:available_locales).and_return(["es"]) .to receive(:locales).and_return(["es"])
expect(remote_translation).to be_valid expect(remote_translation).to be_valid
end end
it "is valid with a locale that uses a different name in the remote service" do 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) allow(RemoteTranslations::Microsoft::AvailableLocales).to receive(:remote_available_locales)
.and_return(["pt"]) .and_return(["pt"])

View File

@@ -11,7 +11,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
Setting["feature.remote_translations"] = true Setting["feature.remote_translations"] = true
available_locales_response = %w[de en es fr pt zh-Hans] available_locales_response = %w[de en es fr pt zh-Hans]
expect(RemoteTranslations::Microsoft::AvailableLocales) expect(RemoteTranslations::Microsoft::AvailableLocales)
.to receive(:available_locales).at_most(4).times .to receive(:locales).at_most(4).times
.and_return(available_locales_response) .and_return(available_locales_response)
allow(Rails.application.secrets).to receive(:microsoft_api_key).and_return("123") allow(Rails.application.secrets).to receive(:microsoft_api_key).and_return("123")
end end

View File

@@ -145,7 +145,7 @@ RSpec.configure do |config|
config.before(:each, :remote_translations) do config.before(:each, :remote_translations) do
allow(RemoteTranslations::Microsoft::AvailableLocales) 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 end
config.around(:each, :with_frozen_time) do |example| config.around(:each, :with_frozen_time) do |example|