Merged updates from trunk into stable branch
[feedcatcher.git] / vendor / rails / activesupport / lib / active_support / vendor / i18n-0.1.3 / test / i18n_test.rb
1 $:.unshift "lib"
2
3 require 'rubygems'
4 require 'test/unit'
5 require 'mocha'
6 require 'i18n'
7 require 'active_support'
8
9 class I18nTest < Test::Unit::TestCase
10 def setup
11 I18n.backend.store_translations :'en', {
12 :currency => {
13 :format => {
14 :separator => '.',
15 :delimiter => ',',
16 }
17 }
18 }
19 end
20
21 def test_uses_simple_backend_set_by_default
22 assert I18n.backend.is_a?(I18n::Backend::Simple)
23 end
24
25 def test_can_set_backend
26 assert_nothing_raised{ I18n.backend = self }
27 assert_equal self, I18n.backend
28 I18n.backend = I18n::Backend::Simple.new
29 end
30
31 def test_uses_en_us_as_default_locale_by_default
32 assert_equal 'en', I18n.default_locale
33 end
34
35 def test_can_set_default_locale
36 assert_nothing_raised{ I18n.default_locale = 'de' }
37 assert_equal 'de', I18n.default_locale
38 I18n.default_locale = 'en'
39 end
40
41 def test_uses_default_locale_as_locale_by_default
42 assert_equal I18n.default_locale, I18n.locale
43 end
44
45 def test_can_set_locale_to_thread_current
46 assert_nothing_raised{ I18n.locale = 'de' }
47 assert_equal 'de', I18n.locale
48 assert_equal 'de', Thread.current[:locale]
49 I18n.locale = 'en'
50 end
51
52 def test_can_set_exception_handler
53 assert_nothing_raised{ I18n.exception_handler = :custom_exception_handler }
54 I18n.exception_handler = :default_exception_handler # revert it
55 end
56
57 def test_uses_custom_exception_handler
58 I18n.exception_handler = :custom_exception_handler
59 I18n.expects(:custom_exception_handler)
60 I18n.translate :bogus
61 I18n.exception_handler = :default_exception_handler # revert it
62 end
63
64 def test_delegates_translate_to_backend
65 I18n.backend.expects(:translate).with 'de', :foo, {}
66 I18n.translate :foo, :locale => 'de'
67 end
68
69 def test_delegates_localize_to_backend
70 I18n.backend.expects(:localize).with 'de', :whatever, :default
71 I18n.localize :whatever, :locale => 'de'
72 end
73
74 def test_translate_given_no_locale_uses_i18n_locale
75 I18n.backend.expects(:translate).with 'en', :foo, {}
76 I18n.translate :foo
77 end
78
79 def test_translate_on_nested_symbol_keys_works
80 assert_equal ".", I18n.t(:'currency.format.separator')
81 end
82
83 def test_translate_with_nested_string_keys_works
84 assert_equal ".", I18n.t('currency.format.separator')
85 end
86
87 def test_translate_with_array_as_scope_works
88 assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
89 end
90
91 def test_translate_with_array_containing_dot_separated_strings_as_scope_works
92 assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
93 end
94
95 def test_translate_with_key_array_and_dot_separated_scope_works
96 assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format')
97 end
98
99 def test_translate_with_dot_separated_key_array_and_scope_works
100 assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency')
101 end
102
103 def test_translate_with_options_using_scope_works
104 I18n.backend.expects(:translate).with('de', :precision, :scope => :"currency.format")
105 I18n.with_options :locale => 'de', :scope => :'currency.format' do |locale|
106 locale.t :precision
107 end
108 end
109
110 # def test_translate_given_no_args_raises_missing_translation_data
111 # assert_equal "translation missing: en, no key", I18n.t
112 # end
113
114 def test_translate_given_a_bogus_key_raises_missing_translation_data
115 assert_equal "translation missing: en, bogus", I18n.t(:bogus)
116 end
117
118 def test_localize_nil_raises_argument_error
119 assert_raise(I18n::ArgumentError) { I18n.l nil }
120 end
121
122 def test_localize_object_raises_argument_error
123 assert_raise(I18n::ArgumentError) { I18n.l Object.new }
124 end
125 end