localization_spec.rb 888 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe 'Localization' do
  4. around do |example|
  5. I18n.with_locale(I18n.locale) do
  6. example.run
  7. end
  8. end
  9. it 'uses a specific region when provided' do
  10. headers = { 'Accept-Language' => 'zh-HK' }
  11. get '/auth/sign_in', headers: headers
  12. expect(response.body).to include(
  13. I18n.t('auth.login', locale: 'zh-HK')
  14. )
  15. end
  16. it 'falls back to a locale when region missing' do
  17. headers = { 'Accept-Language' => 'es-FAKE' }
  18. get '/auth/sign_in', headers: headers
  19. expect(response.body).to include(
  20. I18n.t('auth.login', locale: 'es')
  21. )
  22. end
  23. it 'falls back to english when locale is missing' do
  24. headers = { 'Accept-Language' => '12-FAKE' }
  25. get '/auth/sign_in', headers: headers
  26. expect(response.body).to include(
  27. I18n.t('auth.login', locale: 'en')
  28. )
  29. end
  30. end