mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Validate interpolation keys used in translation overrides.
https://meta.discourse.org/t/discobot-translation-missing-error/64429/6?u=tgxworld
This commit is contained in:
@@ -1,6 +1,40 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe TranslationOverride do
|
||||
context 'validations' do
|
||||
describe '#value' do
|
||||
before do
|
||||
described_class.any_instance.expects(:lookup_original_text)
|
||||
.returns('%{first} %{second}')
|
||||
end
|
||||
|
||||
describe 'when interpolation keys are missing' do
|
||||
it 'should not be valid' do
|
||||
translation_override = TranslationOverride.upsert!(
|
||||
I18n.locale, 'some_key', '%{first}'
|
||||
)
|
||||
|
||||
expect(translation_override.errors.full_messages).to include(I18n.t(
|
||||
'activerecord.errors.models.translation_overrides.attributes.value.missing_interpolation_keys',
|
||||
keys: 'second'
|
||||
))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when interpolation keys are invalid' do
|
||||
it 'should not be valid' do
|
||||
translation_override = TranslationOverride.upsert!(
|
||||
I18n.locale, 'some_key', '%{first} %{second} %{third}'
|
||||
)
|
||||
|
||||
expect(translation_override.errors.full_messages).to include(I18n.t(
|
||||
'activerecord.errors.models.translation_overrides.attributes.value.invalid_interpolation_keys',
|
||||
keys: 'third'
|
||||
))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "upserts values" do
|
||||
TranslationOverride.upsert!('en', 'some.key', 'some value')
|
||||
@@ -19,4 +53,3 @@ describe TranslationOverride do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user