debian-mirror-gitlab/spec/controllers/concerns/preferred_language_switcher_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.3 KiB
Ruby
Raw Normal View History

2023-01-13 00:05:48 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe PreferredLanguageSwitcher, type: :controller do
controller(ActionController::Base) do
include PreferredLanguageSwitcher # rubocop:disable RSpec/DescribedClass
before_action :init_preferred_language, only: :new
def new
render html: 'new page'
end
end
context 'when first visit' do
before do
get :new
end
it 'sets preferred_language to default' do
expect(cookies[:preferred_language]).to eq Gitlab::CurrentSettings.default_preferred_language
end
end
context 'when preferred language in cookies has been modified' do
let(:user_preferred_language) { nil }
before do
cookies[:preferred_language] = user_preferred_language
get :new
end
context 'with a valid value' do
let(:user_preferred_language) { 'zh_CN' }
it 'keeps preferred language unchanged' do
expect(cookies[:preferred_language]).to eq user_preferred_language
end
end
context 'with an invalid value' do
let(:user_preferred_language) { 'xxx' }
it 'sets preferred_language to default' do
expect(cookies[:preferred_language]).to eq Gitlab::CurrentSettings.default_preferred_language
end
end
end
end