2019-11-07 22:06:48 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-04 19:44:19 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::I18n do
|
2021-05-09 20:10:37 -04:00
|
|
|
let(:user) { create(:user, preferred_language: :es) }
|
2017-05-04 19:44:19 -04:00
|
|
|
|
2020-07-31 17:10:12 -04:00
|
|
|
describe '.selectable_locales' do
|
2021-05-09 20:10:37 -04:00
|
|
|
include StubLanguagesTranslationPercentage
|
|
|
|
|
|
|
|
it 'does not return languages with low translation levels' do
|
|
|
|
stub_languages_translation_percentage(pt_BR: 0, en: 100, es: 65)
|
|
|
|
|
|
|
|
expect(described_class.selectable_locales).to eq({
|
|
|
|
'en' => 'English',
|
|
|
|
'es' => 'Spanish - español'
|
|
|
|
})
|
2020-07-31 17:10:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-25 11:22:45 -04:00
|
|
|
describe '.locale=' do
|
2017-06-14 14:18:56 -04:00
|
|
|
after do
|
|
|
|
described_class.use_default_locale
|
|
|
|
end
|
2017-05-04 19:44:19 -04:00
|
|
|
|
2017-05-25 11:22:45 -04:00
|
|
|
it 'sets the locale based on current user preferred language' do
|
|
|
|
described_class.locale = user.preferred_language
|
|
|
|
|
|
|
|
expect(FastGettext.locale).to eq('es')
|
|
|
|
expect(::I18n.locale).to eq(:es)
|
2017-05-04 19:44:19 -04:00
|
|
|
end
|
2017-05-25 11:22:45 -04:00
|
|
|
end
|
2017-05-04 19:44:19 -04:00
|
|
|
|
2017-05-25 11:22:45 -04:00
|
|
|
describe '.use_default_locale' do
|
|
|
|
it 'resets the locale to the default language' do
|
|
|
|
described_class.locale = user.preferred_language
|
2017-05-04 19:44:19 -04:00
|
|
|
|
2017-05-25 11:22:45 -04:00
|
|
|
described_class.use_default_locale
|
2017-05-04 19:44:19 -04:00
|
|
|
|
2017-05-25 11:22:45 -04:00
|
|
|
expect(FastGettext.locale).to eq('en')
|
|
|
|
expect(::I18n.locale).to eq(:en)
|
2017-05-04 19:44:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|