Files
nairobi/spec/models/remote_translation_spec.rb
Javi Martín e7fcca9b47 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.
2020-04-28 15:45:32 +02:00

58 lines
1.6 KiB
Ruby

require "rails_helper"
describe RemoteTranslation do
let(:remote_translation) { build(:remote_translation, locale: :es) }
it "is valid" do
expect(remote_translation).to be_valid
end
it "is valid without error_message" do
remote_translation.error_message = nil
expect(remote_translation).to be_valid
end
it "is not valid without to" do
remote_translation.locale = nil
expect(remote_translation).not_to be_valid
end
it "is not valid without a remote_translatable_id" do
remote_translation.remote_translatable_id = nil
expect(remote_translation).not_to be_valid
end
it "is not valid without a remote_translatable_type" do
remote_translation.remote_translatable_type = nil
expect(remote_translation).not_to be_valid
end
it "is not valid without an available_locales" do
remote_translation.locale = "unavailable_locale"
expect(remote_translation).not_to be_valid
end
it "is not valid when exists a translation for locale" do
remote_translation.locale = :en
expect(remote_translation).not_to be_valid
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
it "after create enqueue Delayed Job" do
expect { remote_translation.save }.to change { Delayed::Job.count }.by(1)
end
end
end