diff options
author | elijah <elijah@riseup.net> | 2013-12-22 01:45:41 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2013-12-22 02:00:49 -0800 |
commit | 665964bcbba69829a4ff1e7d7bd936f90d49b3f7 (patch) | |
tree | bc5356220eaca2465bd135f45edf8000d6c254be /test/integration/locale_path_test.rb | |
parent | 5bf1462140a7aa17ea815ccc5105ace6fa878d83 (diff) |
locale prefix support:
* set locale based on request header
* enforce locale path prefix when current locale is not the default
* note: don't use root_path anymore, instead use home_path
Diffstat (limited to 'test/integration/locale_path_test.rb')
-rw-r--r-- | test/integration/locale_path_test.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/integration/locale_path_test.rb b/test/integration/locale_path_test.rb new file mode 100644 index 0000000..2c43ab2 --- /dev/null +++ b/test/integration/locale_path_test.rb @@ -0,0 +1,51 @@ +require 'test_helper' + +# +# Test how we handle redirections and locales. +# +# The basic rules are: +# +# (1) If the browser header Accept-Language matches default locale, then don't do a locale prefix. +# (2) If browser locale is supported in available_locales, but is not the default, then redirect. +# (3) If browser locale is not in available_locales, use the default locale with no prefix. +# +# Settings in defaults.yml +# +# default_locale: :en +# available_locales: +# - :en +# - :de +# +# NOTE: Although the browser sends the header Accept-Language, this is parsed by +# ruby as HTTP_ACCEPT_LANGUAGE +# + +class LocalePathTest < ActionDispatch::IntegrationTest + test "redirect if accept-language is not default locale" do + get_via_redirect '/', {}, 'HTTP_ACCEPT_LANGUAGE' => 'de' + assert_equal '/de', path + assert_equal({:locale => :de}, @controller.default_url_options) + end + + test "no locale prefix" do + get_via_redirect '/', {}, 'HTTP_ACCEPT_LANGUAGE' => 'en' + assert_equal '/', path + assert_equal({:locale => nil}, @controller.default_url_options) + + get_via_redirect '/', {}, 'HTTP_ACCEPT_LANGUAGE' => 'pt' + assert_equal '/', path + assert_equal({:locale => nil}, @controller.default_url_options) + end + + test "no redirect if locale explicit" do + get_via_redirect '/de', {}, 'HTTP_ACCEPT_LANGUAGE' => 'en' + assert_equal '/de', path + assert_equal({:locale => :de}, @controller.default_url_options) + end + + test "strip prefix from url options if locale is default" do + get_via_redirect '/en', {}, 'HTTP_ACCEPT_LANGUAGE' => 'en' + assert_equal '/en', path + assert_equal({:locale => nil}, @controller.default_url_options) + end +end
\ No newline at end of file |