Use more generic locale as fallback for rules (#34756)

This commit is contained in:
Claire 2025-05-21 18:22:54 +02:00 committed by GitHub
parent 97b9e8849d
commit 6ab96ba647
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 4 deletions

View file

@ -36,4 +36,15 @@ RSpec.describe Rule do
.to change { described_class.ordered.pluck(:text) }.from(%w(foo baz bar)).to(%w(foo bar baz))
end
end
describe '#translation_for' do
let!(:rule) { Fabricate(:rule, text: 'This is a rule', hint: 'This is an explanation of the rule') }
let!(:translation) { Fabricate(:rule_translation, rule: rule, text: 'Ceci est une règle', hint: 'Ceci est une explication de la règle', language: 'fr') }
it 'returns the expected translation, including fallbacks' do
expect(rule.translation_for(:en)).to have_attributes(text: rule.text, hint: rule.hint)
expect(rule.translation_for(:fr)).to have_attributes(text: translation.text, hint: translation.hint)
expect(rule.translation_for(:'fr-CA')).to have_attributes(text: translation.text, hint: translation.hint)
end
end
end