|
|
@ -7,16 +7,10 @@ describe ApplicationController, type: :controller do |
|
|
|
include Localized |
|
|
|
include Localized |
|
|
|
|
|
|
|
|
|
|
|
def success |
|
|
|
def success |
|
|
|
head 200 |
|
|
|
render plain: I18n.locale, status: 200 |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
around do |example| |
|
|
|
|
|
|
|
current_locale = I18n.locale |
|
|
|
|
|
|
|
example.run |
|
|
|
|
|
|
|
I18n.locale = current_locale |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
routes.draw { get 'success' => 'anonymous#success' } |
|
|
|
routes.draw { get 'success' => 'anonymous#success' } |
|
|
|
end |
|
|
|
end |
|
|
@ -25,19 +19,19 @@ describe ApplicationController, type: :controller do |
|
|
|
it 'sets available and preferred language' 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(response.body).to eq 'fa' |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'sets available and compatible language if none of available languages are preferred' do |
|
|
|
it 'sets available and compatible language if 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(response.body).to eq 'fa' |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
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(response.body).to eq 'en' |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -48,7 +42,7 @@ describe ApplicationController, type: :controller do |
|
|
|
sign_in(user) |
|
|
|
sign_in(user) |
|
|
|
get 'success' |
|
|
|
get 'success' |
|
|
|
|
|
|
|
|
|
|
|
expect(I18n.locale).to eq :ca |
|
|
|
expect(response.body).to eq 'ca' |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|