Check remote translations locales at runtime
We were evaluating its value when the server starts. On production enviroments, that could mean weeks or months before the available locales are checked again, and so it would be possible to use a list which is no longer in sync with the list provided by microsoft.
This commit is contained in:
@@ -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.available_locales }}
|
||||||
validate :already_translated_resource
|
validate :already_translated_resource
|
||||||
after_create :enqueue_remote_translation
|
after_create :enqueue_remote_translation
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,18 @@ describe RemoteTranslation do
|
|||||||
expect(remote_translation).not_to be_valid
|
expect(remote_translation).not_to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "checks available locales dynamically" do
|
||||||
|
allow(RemoteTranslations::Microsoft::AvailableLocales)
|
||||||
|
.to receive(:available_locales).and_return(["en"])
|
||||||
|
|
||||||
|
expect(remote_translation).not_to be_valid
|
||||||
|
|
||||||
|
allow(RemoteTranslations::Microsoft::AvailableLocales)
|
||||||
|
.to receive(:available_locales).and_return(["es"])
|
||||||
|
|
||||||
|
expect(remote_translation).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
describe "#enqueue_remote_translation", :delay_jobs do
|
describe "#enqueue_remote_translation", :delay_jobs do
|
||||||
it "after create enqueue Delayed Job" do
|
it "after create enqueue Delayed Job" do
|
||||||
expect { remote_translation.save }.to change { Delayed::Job.count }.by(1)
|
expect { remote_translation.save }.to change { Delayed::Job.count }.by(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user