DEV: Add specs for handling InvalidPluralizationData exception

follow-up to 6d44be51
This commit is contained in:
Gerhard Schlager 2019-05-13 22:07:42 +02:00
parent bbab60fa9b
commit 13e54bca3d
1 changed files with 19 additions and 0 deletions

View File

@ -94,4 +94,23 @@ describe I18n::Backend::DiscourseI18n do
expect(backend.exists?(:ru, :bogus)).to eq(false)
end
end
describe '#pluralize' do
it 'uses fallback locales when a pluralization key is missing' do
SiteSetting.default_locale = 'ru'
backend.store_translations(:ru, items: { one: '%{count} Russian item', other: '%{count} Russian items' })
expect(backend.translate(:ru, :items, count: 1)).to eq('1 Russian item')
expect(backend.translate(:ru, :items, count: 2)).to eq('2 items')
expect(backend.translate(:ru, :items, count: 5)).to eq('5 Russian items')
backend.store_translations(:ru, items: { one: '%{count} Russian item', few: '%{count} Russian items are a few', other: '%{count} Russian items' })
expect(backend.translate(:ru, :items, count: 2)).to eq('2 Russian items are a few')
backend.store_translations(:en, airplanes: { one: '%{count} airplane' })
expect(backend.translate(:ru, :airplanes, count: 1)).to eq('1 airplane')
expect { backend.translate(:ru, :airplanes, count: 2) }.to raise_error(I18n::InvalidPluralizationData)
end
end
end