63c21ac8ab03fab1484b932a1a5d34cf84788cd0
[packages/precise/mcollective.git] / lib / mcollective / vendor / i18n / lib / i18n / tests / lookup.rb
1 # encoding: utf-8
2
3 module I18n
4   module Tests
5     module Lookup
6       def setup
7         super
8         I18n.backend.store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' }, :falsy => false, :truthy => true,
9           :string => "a", :array => %w(a b c), :hash => { "a" => "b" })
10       end
11
12       test "lookup: it returns a string" do
13         assert_equal("a", I18n.t(:string))
14       end
15
16       test "lookup: it returns hash" do
17         assert_equal({ :a => "b" }, I18n.t(:hash))
18       end
19
20       test "lookup: it returns a array" do
21         assert_equal(%w(a b c), I18n.t(:array))
22       end
23
24       test "lookup: it returns a native true" do
25         assert I18n.t(:truthy) === true
26       end
27
28       test "lookup: it returns a native false" do
29         assert I18n.t(:falsy) === false
30       end
31
32       test "lookup: given a missing key, no default and no raise option it returns an error message" do
33         assert_equal "translation missing: en.missing", I18n.t(:missing)
34       end
35
36       test "lookup: given a missing key, no default and the raise option it raises MissingTranslationData" do
37         assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
38       end
39
40       test "lookup: does not raise an exception if no translation data is present for the given locale" do
41         assert_nothing_raised { I18n.t(:foo, :locale => :xx) }
42       end
43
44       test "lookup: given an array of keys it translates all of them" do
45         assert_equal %w(bar baz), I18n.t([:bar, :baz], :scope => [:foo])
46       end
47
48       test "lookup: using a custom scope separator" do
49         # data must have been stored using the custom separator when using the ActiveRecord backend
50         I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' })
51         assert_equal 'bar', I18n.t('foo|bar', :separator => '|')
52       end
53
54       # In fact it probably *should* fail but Rails currently relies on using the default locale instead.
55       # So we'll stick to this for now until we get it fixed in Rails.
56       test "lookup: given nil as a locale it does not raise but use the default locale" do
57         # assert_raise(I18n::InvalidLocale) { I18n.t(:bar, :locale => nil) }
58         assert_nothing_raised { I18n.t(:bar, :locale => nil) }
59       end
60
61       test "lookup: a resulting String is not frozen" do
62         assert !I18n.t(:string).frozen?
63       end
64
65       test "lookup: a resulting Array is not frozen" do
66         assert !I18n.t(:array).frozen?
67       end
68
69       test "lookup: a resulting Hash is not frozen" do
70         assert !I18n.t(:hash).frozen?
71       end
72     end
73   end
74 end