locale_setting_test.rb
906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require "#{File.dirname(__FILE__)}/../test_helper"
class LocaleSettingTest < ActionController::IntegrationTest
def setup
# reset GetText before every test
GetText.locale = nil
end
should 'detect locale from the browser' do
# user has pt_BR
get '/', { }, { 'HTTP_ACCEPT_LANGUAGE' => 'pt-br, en' }
assert_equal 'pt_BR', GetText.locale.to_s
# user now wants en
get '/', { }, { 'HTTP_ACCEPT_LANGUAGE' => 'en' }
assert_equal 'en', GetText.locale.to_s
end
should 'be able to force locale' do
# set locale to pt_BR
get '/', :lang => 'pt_BR'
assert_equal 'pt_BR', GetText.locale.to_s
# locale is kept
get '/'
assert_equal 'pt_BR', GetText.locale.to_s
# changing back
get '/', :lang => 'en'
assert_equal 'en', GetText.locale.to_s
# locale is kept again
get '/'
assert_equal 'en', GetText.locale.to_s
end
end