~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb

  • Committer: Michael Forrest
  • Date: 2010-10-15 16:28:50 UTC
  • Revision ID: michael.forrest@canonical.com-20101015162850-tj2vchanv0kr0dun
refrozeĀ gems

Show diffs side-by-side

added added

removed removed

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