@ -16,51 +16,26 @@ describe ApplicationController, type: :controller do
end
end
shared_examples 'default locale' do
shared_examples 'default locale' do
context 'when DEFAULT_LOCALE environment variable is set' do
after { I18n . locale = I18n . default_locale }
around do | example |
ClimateControl . modify 'DEFAULT_LOCALE' = > 'ca' , & example . method ( :run )
I18n . locale = I18n . default_locale
end
it 'sets language specified by ENV if preferred' do
request . headers [ 'Accept-Language' ] = 'ca, fa'
get 'success'
expect ( I18n . locale ) . to eq :ca
end
it 'sets available and preferred language if language specified by ENV is not preferred ' do
it 'sets available and preferred language' do
request . headers [ 'Accept-Language' ] = 'ca-ES, fa'
request . headers [ 'Accept-Language' ] = 'ca-ES, fa'
get 'success'
get 'success'
expect ( I18n . locale ) . to eq :fa
expect ( I18n . locale ) . to eq :fa
end
end
it 'sets language specified by ENV if it is compatible and none of available languages are preferred' do
it 'sets available and compatible langauge if none of available languages are preferred' do
request . headers [ 'Accept-Language' ] = 'ca-ES, fa-IR'
get 'success'
expect ( I18n . locale ) . to eq :ca
end
it 'sets available and compatible langauge if language specified by ENV is not compatible none of available languages are preferred' do
request . headers [ 'Accept-Language' ] = 'fa-IR'
request . headers [ 'Accept-Language' ] = 'fa-IR'
get 'success'
get 'success'
expect ( I18n . locale ) . to eq :fa
expect ( I18n . locale ) . to eq :fa
end
end
it 'sets language specified by ENV if none of available languages are compatible' do
request . headers [ 'Accept-Language' ] = ''
get 'success'
expect ( I18n . locale ) . to eq :ca
end
end
context 'when DEFAULT_LOCALE environment variable is not set' do
it 'sets default locale if none of available languages are compatible' do
it 'sets default locale if none of available languages are compatible' do
request . headers [ 'Accept-Language' ] = ''
request . headers [ 'Accept-Language' ] = ''
get 'success'
get 'success'
expect ( I18n . locale ) . to eq :en
expect ( I18n . locale ) . to eq :en
end
end
end
end
end
context 'user with valid locale has signed in' do
context 'user with valid locale has signed in' do
it " sets user's locale " do
it " sets user's locale " do