discourse/spec/jobs/check_translation_overrides_spec.rb
Ted Johansson 7a53fb65da
FIX: Don't show admin warnings about deleted translation overrides (#22614)
We recently introduced this advice to admins when some translation overrides are outdated or using unknown interpolation keys:

However we missed the case where the original translation key has been renamed or altogether removed. When this happens they are no longer visible in the admin interface, leading to the confusing situation where we say there are outdated translations, but none are shown.

Because we don't explicitly handle this case, some deleted translations were incorrectly marked as having unknown interpolation keys. (This is because I18n.t will return a string like "Translation missing: foo", which obviously has no interpolation keys inside.)

This change adds an additional status, deprecated for TranslationOverride, and the job that checks them will check for this status first, taking precedence over invalid_interpolation_keys. Since the advice only checks for the outdated and invalid_interpolation_keys statuses, this fixes the problem.
2023-07-14 16:52:39 +08:00

37 lines
1.4 KiB
Ruby

# frozen_string_literal: true
RSpec.describe Jobs::CheckTranslationOverrides do
fab!(:up_to_date_translation) { Fabricate(:translation_override, translation_key: "title") }
fab!(:deprecated_translation) { Fabricate(:translation_override, translation_key: "foo.bar") }
fab!(:outdated_translation) do
Fabricate(:translation_override, translation_key: "posts", original_translation: "outdated")
end
fab!(:invalid_translation) { Fabricate(:translation_override, translation_key: "topics") }
it "marks translations with keys which no longer exist in the locale file" do
expect { described_class.new.execute({}) }.to change {
deprecated_translation.reload.status
}.from("up_to_date").to("deprecated")
end
it "marks translations with invalid interpolation keys" do
invalid_translation.update_attribute("value", "Invalid %{foo}")
expect { described_class.new.execute({}) }.to change { invalid_translation.reload.status }.from(
"up_to_date",
).to("invalid_interpolation_keys")
end
it "marks translations that are outdated" do
expect { described_class.new.execute({}) }.to change {
outdated_translation.reload.status
}.from("up_to_date").to("outdated")
end
it "does not mark up to date translations" do
expect { described_class.new.execute({}) }.not_to change {
up_to_date_translation.reload.status
}
end
end