2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
2010-04-08 21:11:26 -04:00
|
|
|
|
|
|
|
class LocalizedController < ActionController::Base
|
|
|
|
def hello_world
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class LocalizedTemplatesTest < ActionController::TestCase
|
|
|
|
tests LocalizedController
|
|
|
|
|
2014-05-28 09:50:30 -04:00
|
|
|
setup do
|
|
|
|
@old_locale = I18n.locale
|
|
|
|
end
|
|
|
|
|
|
|
|
teardown do
|
|
|
|
I18n.locale = @old_locale
|
|
|
|
end
|
|
|
|
|
2010-04-08 21:11:26 -04:00
|
|
|
def test_localized_template_is_used
|
|
|
|
I18n.locale = :de
|
|
|
|
get :hello_world
|
2014-12-05 00:49:38 -05:00
|
|
|
assert_equal "Guten Tag", @response.body
|
2010-04-08 21:11:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_default_locale_template_is_used_when_locale_is_missing
|
|
|
|
I18n.locale = :dk
|
|
|
|
get :hello_world
|
|
|
|
assert_equal "Hello World", @response.body
|
|
|
|
end
|
2013-03-14 17:02:20 -04:00
|
|
|
|
|
|
|
def test_use_fallback_locales
|
|
|
|
I18n.locale = :"de-AT"
|
2015-01-31 23:12:37 -05:00
|
|
|
I18n.backend.class.include(I18n::Backend::Fallbacks)
|
2013-03-14 17:02:20 -04:00
|
|
|
I18n.fallbacks[:"de-AT"] = [:de]
|
|
|
|
|
|
|
|
get :hello_world
|
2014-12-05 00:49:38 -05:00
|
|
|
assert_equal "Guten Tag", @response.body
|
2013-03-14 17:02:20 -04:00
|
|
|
end
|
2013-11-29 06:26:12 -05:00
|
|
|
|
|
|
|
def test_localized_template_has_correct_header_with_no_format_in_template_name
|
|
|
|
I18n.locale = :it
|
|
|
|
get :hello_world
|
|
|
|
assert_equal "Ciao Mondo", @response.body
|
2019-04-17 02:37:16 -04:00
|
|
|
assert_equal "text/html", @response.media_type
|
2013-11-29 06:26:12 -05:00
|
|
|
end
|
2013-01-21 09:24:03 -05:00
|
|
|
end
|