~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_exceptions_test.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

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 I18nExceptionsTest < Test::Unit::TestCase
9
 
  def test_invalid_locale_stores_locale
10
 
    force_invalid_locale
11
 
  rescue I18n::ArgumentError => e
12
 
    assert_nil e.locale
13
 
  end
14
 
 
15
 
  def test_invalid_locale_message
16
 
    force_invalid_locale
17
 
  rescue I18n::ArgumentError => e
18
 
    assert_equal 'nil is not a valid locale', e.message
19
 
  end
20
 
 
21
 
  def test_missing_translation_data_stores_locale_key_and_options
22
 
    force_missing_translation_data
23
 
  rescue I18n::ArgumentError => e
24
 
    options = {:scope => :bar}
25
 
    assert_equal 'de', e.locale
26
 
    assert_equal :foo, e.key
27
 
    assert_equal options, e.options
28
 
  end
29
 
 
30
 
  def test_missing_translation_data_message
31
 
    force_missing_translation_data
32
 
  rescue I18n::ArgumentError => e
33
 
    assert_equal 'translation missing: de, bar, foo', e.message
34
 
  end
35
 
 
36
 
  def test_invalid_pluralization_data_stores_entry_and_count
37
 
    force_invalid_pluralization_data
38
 
  rescue I18n::ArgumentError => e
39
 
    assert_equal [:bar], e.entry
40
 
    assert_equal 1, e.count
41
 
  end
42
 
 
43
 
  def test_invalid_pluralization_data_message
44
 
    force_invalid_pluralization_data
45
 
  rescue I18n::ArgumentError => e
46
 
    assert_equal 'translation data [:bar] can not be used with :count => 1', e.message
47
 
  end
48
 
 
49
 
  def test_missing_interpolation_argument_stores_key_and_string
50
 
    force_missing_interpolation_argument
51
 
  rescue I18n::ArgumentError => e
52
 
    assert_equal 'bar', e.key
53
 
    assert_equal "{{bar}}", e.string
54
 
  end
55
 
 
56
 
  def test_missing_interpolation_argument_message
57
 
    force_missing_interpolation_argument
58
 
  rescue I18n::ArgumentError => e
59
 
    assert_equal 'interpolation argument bar missing in "{{bar}}"', e.message
60
 
  end
61
 
 
62
 
  def test_reserved_interpolation_key_stores_key_and_string
63
 
    force_reserved_interpolation_key
64
 
  rescue I18n::ArgumentError => e
65
 
    assert_equal 'scope', e.key
66
 
    assert_equal "{{scope}}", e.string
67
 
  end
68
 
 
69
 
  def test_reserved_interpolation_key_message
70
 
    force_reserved_interpolation_key
71
 
  rescue I18n::ArgumentError => e
72
 
    assert_equal 'reserved key "scope" used in "{{scope}}"', e.message
73
 
  end
74
 
 
75
 
  private
76
 
    def force_invalid_locale
77
 
      I18n.backend.translate nil, :foo
78
 
    end
79
 
 
80
 
    def force_missing_translation_data
81
 
      I18n.backend.store_translations 'de', :bar => nil
82
 
      I18n.backend.translate 'de', :foo, :scope => :bar
83
 
    end
84
 
 
85
 
    def force_invalid_pluralization_data
86
 
      I18n.backend.store_translations 'de', :foo => [:bar]
87
 
      I18n.backend.translate 'de', :foo, :count => 1
88
 
    end
89
 
 
90
 
    def force_missing_interpolation_argument
91
 
      I18n.backend.store_translations 'de', :foo => "{{bar}}"
92
 
      I18n.backend.translate 'de', :foo, :baz => 'baz'
93
 
    end
94
 
 
95
 
    def force_reserved_interpolation_key
96
 
      I18n.backend.store_translations 'de', :foo => "{{scope}}"
97
 
      I18n.backend.translate 'de', :foo, :baz => 'baz'
98
 
    end
99
 
end
 
 
b'\\ No newline at end of file'