parent
bd87e66679
commit
bd1545de5e
4 changed files with 17 additions and 21 deletions
|
@ -7,16 +7,10 @@ describe ApplicationController, type: :controller do
|
|||
include Localized
|
||||
|
||||
def success
|
||||
head 200
|
||||
render plain: I18n.locale, status: 200
|
||||
end
|
||||
end
|
||||
|
||||
around do |example|
|
||||
current_locale = I18n.locale
|
||||
example.run
|
||||
I18n.locale = current_locale
|
||||
end
|
||||
|
||||
before do
|
||||
routes.draw { get 'success' => 'anonymous#success' }
|
||||
end
|
||||
|
@ -25,19 +19,19 @@ describe ApplicationController, type: :controller do
|
|||
it 'sets available and preferred language' do
|
||||
request.headers['Accept-Language'] = 'ca-ES, fa'
|
||||
get 'success'
|
||||
expect(I18n.locale).to eq :fa
|
||||
expect(response.body).to eq 'fa'
|
||||
end
|
||||
|
||||
it 'sets available and compatible language if none of available languages are preferred' do
|
||||
request.headers['Accept-Language'] = 'fa-IR'
|
||||
get 'success'
|
||||
expect(I18n.locale).to eq :fa
|
||||
expect(response.body).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
|
||||
expect(response.body).to eq 'en'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -48,7 +42,7 @@ describe ApplicationController, type: :controller do
|
|||
sign_in(user)
|
||||
get 'success'
|
||||
|
||||
expect(I18n.locale).to eq :ca
|
||||
expect(response.body).to eq 'ca'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue