diff options
Diffstat (limited to 'spec/controllers/concerns')
-rw-r--r-- | spec/controllers/concerns/onboarding/status_spec.rb | 28 | ||||
-rw-r--r-- | spec/controllers/concerns/preferred_language_switcher_spec.rb | 74 |
2 files changed, 70 insertions, 32 deletions
diff --git a/spec/controllers/concerns/onboarding/status_spec.rb b/spec/controllers/concerns/onboarding/status_spec.rb index b14346dc052..fe7c5ac6346 100644 --- a/spec/controllers/concerns/onboarding/status_spec.rb +++ b/spec/controllers/concerns/onboarding/status_spec.rb @@ -75,32 +75,4 @@ RSpec.describe Onboarding::Status, feature_category: :onboarding do it { is_expected.to eq(last_member_source) } end end - - describe '#invite_with_tasks_to_be_done?' do - subject { described_class.new(nil, nil, user).invite_with_tasks_to_be_done? } - - context 'when there are tasks_to_be_done with one member' do - let_it_be(:member) { create(:group_member, user: user, tasks_to_be_done: tasks_to_be_done) } - - it { is_expected.to eq(true) } - end - - context 'when there are multiple members and the tasks_to_be_done is on only one of them' do - before do - create(:group_member, user: user, tasks_to_be_done: tasks_to_be_done) - end - - it { is_expected.to eq(true) } - end - - context 'when there are no tasks_to_be_done' do - it { is_expected.to eq(false) } - end - - context 'when there are no members' do - let_it_be(:user) { build_stubbed(:user) } - - it { is_expected.to eq(false) } - end - end end diff --git a/spec/controllers/concerns/preferred_language_switcher_spec.rb b/spec/controllers/concerns/preferred_language_switcher_spec.rb index 40d6ac10c37..4ceb6fa312e 100644 --- a/spec/controllers/concerns/preferred_language_switcher_spec.rb +++ b/spec/controllers/concerns/preferred_language_switcher_spec.rb @@ -13,13 +13,79 @@ RSpec.describe PreferredLanguageSwitcher, type: :controller do end end + subject { cookies[:preferred_language] } + context 'when first visit' do + let(:glm_source) { 'about.gitlab.com' } + let(:accept_language_header) { nil } + before do - get :new + request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language_header + + get :new, params: { glm_source: glm_source } end it 'sets preferred_language to default' do - expect(cookies[:preferred_language]).to eq Gitlab::CurrentSettings.default_preferred_language + expect(subject).to eq Gitlab::CurrentSettings.default_preferred_language + end + + context 'when language param is valid' do + let(:glm_source) { 'about.gitlab.com/fr-fr/' } + + it 'sets preferred_language accordingly' do + expect(subject).to eq 'fr' + end + + context 'when language param is invalid' do + let(:glm_source) { 'about.gitlab.com/ko-ko/' } + + it 'sets preferred_language to default' do + expect(subject).to eq Gitlab::CurrentSettings.default_preferred_language + end + end + end + + context 'when browser preferred language is not english' do + context 'with selectable language' do + let(:accept_language_header) { 'zh-CN,zh;q=0.8,zh-TW;q=0.7' } + + it 'sets preferred_language accordingly' do + expect(subject).to eq 'zh_CN' + end + end + + context 'with unselectable language' do + let(:accept_language_header) { 'nl-NL;q=0.8' } + + it 'sets preferred_language to default' do + expect(subject).to eq Gitlab::CurrentSettings.default_preferred_language + end + end + + context 'with empty string in language header' do + let(:accept_language_header) { '' } + + it 'sets preferred_language to default' do + expect(subject).to eq Gitlab::CurrentSettings.default_preferred_language + end + end + + context 'with language header without dashes' do + let(:accept_language_header) { 'fr;q=8' } + + it 'sets preferred_language accordingly' do + expect(subject).to eq 'fr' + end + end + end + + context 'when language params and language header are both valid' do + let(:accept_language_header) { 'zh-CN,zh;q=0.8,zh-TW;q=0.7' } + let(:glm_source) { 'about.gitlab.com/fr-fr/' } + + it 'sets preferred_language according to language params' do + expect(subject).to eq 'fr' + end end end @@ -36,7 +102,7 @@ RSpec.describe PreferredLanguageSwitcher, type: :controller do let(:user_preferred_language) { 'zh_CN' } it 'keeps preferred language unchanged' do - expect(cookies[:preferred_language]).to eq user_preferred_language + expect(subject).to eq user_preferred_language end end @@ -44,7 +110,7 @@ RSpec.describe PreferredLanguageSwitcher, type: :controller do let(:user_preferred_language) { 'xxx' } it 'sets preferred_language to default' do - expect(cookies[:preferred_language]).to eq Gitlab::CurrentSettings.default_preferred_language + expect(subject).to eq Gitlab::CurrentSettings.default_preferred_language end end end |