081dcbd14e9d79398cac08b0484a61df10b11b39
[packages/precise/mcollective.git] / lib / mcollective / vendor / i18n / lib / i18n / tests / defaults.rb
1 # encoding: utf-8
2
3 module I18n
4   module Tests
5     module Defaults
6       def setup
7         super
8         I18n.backend.store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' })
9       end
10
11       test "defaults: given nil as a key it returns the given default" do
12         assert_equal 'default', I18n.t(nil, :default => 'default')
13       end
14
15       test "defaults: given a symbol as a default it translates the symbol" do
16         assert_equal 'bar', I18n.t(nil, :default => :'foo.bar')
17       end
18
19       test "defaults: given a symbol as a default and a scope it stays inside the scope when looking up the symbol" do
20         assert_equal 'bar', I18n.t(:missing, :default => :bar, :scope => :foo)
21       end
22
23       test "defaults: given an array as a default it returns the first match" do
24         assert_equal 'bar', I18n.t(:does_not_exist, :default => [:does_not_exist_2, :'foo.bar'])
25       end
26
27       test "defaults: given an array of missing keys it raises a MissingTranslationData exception" do
28         assert_raise I18n::MissingTranslationData do
29           I18n.t(:does_not_exist, :default => [:does_not_exist_2, :does_not_exist_3], :raise => true)
30         end
31       end
32
33       test "defaults: using a custom scope separator" do
34         # data must have been stored using the custom separator when using the ActiveRecord backend
35         I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' })
36         assert_equal 'bar', I18n.t(nil, :default => :'foo|bar', :separator => '|')
37       end
38     end
39   end
40 end