1
0
mirror of https://github.com/funamitech/mastodon synced 2024-11-30 07:49:04 +09:00
YuruToot/spec/controllers/concerns/localized_spec.rb
Akihiko Odaki 51d760960c Set the default locale in config (#6580)
Previously the default locale was set by Localized concern for controllers,
but it was not enforced for mailers.

config is enforced throughout the application and an appropriate place to
set the default locale.
2018-03-04 09:21:35 +01:00

65 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe ApplicationController, type: :controller do
controller do
include Localized
def success
head 200
end
end
before do
routes.draw { get 'success' => 'anonymous#success' }
end
shared_examples 'default locale' do
after { I18n.locale = I18n.default_locale }
it 'sets available and preferred language' do
request.headers['Accept-Language'] = 'ca-ES, fa'
get 'success'
expect(I18n.locale).to eq :fa
end
it 'sets available and compatible langauge if none of available languages are preferred' do
request.headers['Accept-Language'] = 'fa-IR'
get 'success'
expect(I18n.locale).to eq :fa
end
it 'sets default locale if none of available languages are compatible' do
request.headers['Accept-Language'] = ''
get 'success'
expect(I18n.locale).to eq :en
end
end
context 'user with valid locale has signed in' do
it "sets user's locale" do
user = Fabricate(:user, locale: :ca)
sign_in(user)
get 'success'
expect(I18n.locale).to eq :ca
end
end
context 'user with invalid locale has signed in' do
before do
user = Fabricate.build(:user, locale: :invalid)
user.save!(validate: false)
sign_in(user)
end
include_examples 'default locale'
end
context 'user has not signed in' do
include_examples 'default locale'
end
end