globalize2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +4 -0
  2. data/LICENSE +21 -0
  3. data/README.textile +202 -0
  4. data/Rakefile +39 -0
  5. data/VERSION +1 -0
  6. data/generators/db_backend.rb +0 -0
  7. data/generators/templates/db_backend_migration.rb +25 -0
  8. data/globalize2.gemspec +100 -0
  9. data/init.rb +8 -0
  10. data/lib/globalize/backend/chain.rb +102 -0
  11. data/lib/globalize/backend/pluralizing.rb +37 -0
  12. data/lib/globalize/backend/static.rb +61 -0
  13. data/lib/globalize/i18n/missing_translations_log_handler.rb +41 -0
  14. data/lib/globalize/i18n/missing_translations_raise_handler.rb +27 -0
  15. data/lib/globalize/load_path.rb +63 -0
  16. data/lib/globalize/locale/fallbacks.rb +63 -0
  17. data/lib/globalize/locale/language_tag.rb +81 -0
  18. data/lib/globalize/model/active_record.rb +56 -0
  19. data/lib/globalize/model/active_record/adapter.rb +100 -0
  20. data/lib/globalize/model/active_record/translated.rb +174 -0
  21. data/lib/globalize/translation.rb +32 -0
  22. data/lib/locale/root.yml +3 -0
  23. data/lib/rails_edge_load_path_patch.rb +40 -0
  24. data/notes.textile +51 -0
  25. data/test/all.rb +2 -0
  26. data/test/backends/chained_test.rb +175 -0
  27. data/test/backends/pluralizing_test.rb +63 -0
  28. data/test/backends/static_test.rb +147 -0
  29. data/test/data/locale/all.yml +2 -0
  30. data/test/data/locale/de-DE.yml +2 -0
  31. data/test/data/locale/en-US.yml +2 -0
  32. data/test/data/locale/en-US/module.yml +2 -0
  33. data/test/data/locale/fi-FI/module.yml +2 -0
  34. data/test/data/locale/root.yml +0 -0
  35. data/test/data/models.rb +40 -0
  36. data/test/data/no_globalize_schema.rb +11 -0
  37. data/test/data/schema.rb +39 -0
  38. data/test/i18n/missing_translations_test.rb +36 -0
  39. data/test/load_path_test.rb +49 -0
  40. data/test/locale/fallbacks_test.rb +154 -0
  41. data/test/locale/language_tag_test.rb +130 -0
  42. data/test/model/active_record/migration_test.rb +123 -0
  43. data/test/model/active_record/sti_translated_test.rb +75 -0
  44. data/test/model/active_record/translated_test.rb +487 -0
  45. data/test/test_helper.rb +36 -0
  46. data/test/translation_test.rb +54 -0
  47. metadata +116 -0
@@ -0,0 +1,63 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'test_helper' )
2
+ require 'globalize/backend/pluralizing'
3
+
4
+ class PluralizingTest < ActiveSupport::TestCase
5
+ def setup
6
+ @backend = Globalize::Backend::Pluralizing.new
7
+ @cz_pluralizer = lambda{|c| c == 1 ? :one : (2..4).include?(c) ? :few : :other }
8
+ end
9
+
10
+ test "#pluralizer returns the pluralizer for a given locale if defined" do
11
+ assert_instance_of Proc, @backend.pluralizer(:en)
12
+ end
13
+
14
+ test "#pluralizer returns the default pluralizer if no pluralizer is defined for the given locale" do
15
+ assert_equal @backend.pluralizer(:en), @backend.pluralizer(:de)
16
+ end
17
+
18
+ test "#add_pluralizer allows to store a pluralizer per locale" do
19
+ assert_nothing_raised { @backend.add_pluralizer(:cz, @cz_pluralizer) }
20
+ assert_equal @cz_pluralizer, @backend.pluralizer(:cz)
21
+ end
22
+
23
+ end
24
+
25
+ class PluralizePluralizingTest < ActiveSupport::TestCase
26
+ def setup
27
+ @backend = Globalize::Backend::Pluralizing.new
28
+ @cz_pluralizer = lambda{|c| c == 1 ? :one : (2..4).include?(c) ? :few : :other }
29
+ @backend.store_translations :en, :foo => {:one => 'one en foo', :other => 'many en foos'}
30
+ @backend.store_translations :cz, :foo => {:one => 'one cz foo', :few => 'few cz foos', :other => 'many cz foos'}
31
+ end
32
+
33
+ test "looks up the :one translation when count is 1" do
34
+ assert_equal 'one en foo', @backend.translate(:en, :foo, :count => 1)
35
+ end
36
+
37
+ test "looks up the :other translation when count is 2" do
38
+ assert_equal 'many en foos', @backend.translate(:en, :foo, :count => 2)
39
+ end
40
+ end
41
+
42
+ class CzPluralizingTest < ActiveSupport::TestCase
43
+ def setup
44
+ @backend = Globalize::Backend::Pluralizing.new
45
+ @cz_pluralizer = lambda{|c| c == 1 ? :one : (2..4).include?(c) ? :few : :other }
46
+ @backend.store_translations :en, :foo => {:one => 'one en foo', :other => 'many en foos'}
47
+ @backend.store_translations :cz, :foo => {:one => 'one cz foo', :few => 'few cz foos', :other => 'many cz foos'}
48
+ @backend.add_pluralizer(:cz, @cz_pluralizer)
49
+ end
50
+
51
+ test "looks up the :one translation when count is 1 (:cz)" do
52
+ assert_equal 'one cz foo', @backend.translate(:cz, :foo, :count => 1)
53
+ end
54
+
55
+ test "looks up the :few translation when count is 2 (:cz)" do
56
+ assert_equal 'few cz foos', @backend.translate(:cz, :foo, :count => 2)
57
+ end
58
+
59
+ test "looks up the :other translation when count is 5 (:cz)" do
60
+ assert_equal 'many cz foos', @backend.translate(:cz, :foo, :count => 5)
61
+ end
62
+
63
+ end
@@ -0,0 +1,147 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'test_helper' )
2
+ require 'globalize/backend/static'
3
+ require 'globalize/translation'
4
+ require 'action_view'
5
+ include ActionView::Helpers::NumberHelper
6
+
7
+ I18n.locale = :'en-US' # Need to set this, since I18n defaults to 'en'
8
+
9
+ class StaticTest < ActiveSupport::TestCase
10
+ def setup
11
+ I18n.backend = Globalize::Backend::Static.new
12
+ translations = { :"en-US" => { :foo => "foo in en-US", :boz => 'boz', :buz => { :bum => 'bum' } },
13
+ :"en" => { :bar => "bar in en", :skip_last_comma => "false" },
14
+ :"de-DE" => { :baz => "baz in de-DE" },
15
+ :"de" => { :boo => "boo in de", :number => { :currency => { :format => { :unit => '€', :format => '%n %u' } } } } }
16
+ translations.each do |locale, data|
17
+ I18n.backend.store_translations locale, data
18
+ end
19
+ I18n.fallbacks.map :"de-DE" => :"en-US", :he => :en
20
+ end
21
+
22
+ test "returns an instance of Translation:Static" do
23
+ translation = I18n.translate :foo
24
+ assert_instance_of Globalize::Translation::Static, translation
25
+ end
26
+
27
+ test "returns the translation in en-US if present" do
28
+ assert_equal "foo in en-US", I18n.translate(:foo, :locale => :"en-US")
29
+ end
30
+
31
+ test "returns the translation in en if en-US is not present" do
32
+ assert_equal "bar in en", I18n.translate(:bar, :locale => :"en-US")
33
+ end
34
+
35
+ test "returns the translation in de-DE if present" do
36
+ assert_equal "baz in de-DE", I18n.translate(:baz, :locale => :"de-DE")
37
+ end
38
+
39
+ test "returns the translation in de if de-DE is not present" do
40
+ assert_equal "boo in de", I18n.translate(:boo, :locale => :"de-DE")
41
+ end
42
+
43
+ test "returns the translation in en-US if none of de-DE and de are present" do
44
+ assert_equal "foo in en-US", I18n.translate(:foo, :locale => :"de-DE")
45
+ end
46
+
47
+ test "returns the translation in en if none of de-DE, de and en-US are present" do
48
+ assert_equal "bar in en", I18n.translate(:bar, :locale => :"de-DE")
49
+ end
50
+
51
+ test "returns the translation in en if none in he is present" do
52
+ assert_equal "bar in en", I18n.translate(:bar, :locale => :he)
53
+ end
54
+
55
+ test "returns the given default String when the key is not present for any locale" do
56
+ assert_equal "default", I18n.translate(:missing, :default => "default")
57
+ end
58
+
59
+ test "returns the fallback translation for the key if present for a fallback locale" do
60
+ I18n.backend.store_translations :de, :non_default => "non_default in de"
61
+ assert_equal "non_default in de", I18n.translate(:non_default, :default => "default", :locale => :"de-DE")
62
+ end
63
+
64
+ test "returns an array of translations" do
65
+ assert_instance_of Array, I18n.translate([:foo, :boz])
66
+ end
67
+
68
+ test "returns an array of instances of Translation::Static" do
69
+ assert_equal [Globalize::Translation::Static], I18n.translate([:foo, :boz]).map(&:class).uniq
70
+ end
71
+
72
+ test "returns a hash of translations" do
73
+ assert_instance_of Hash, I18n.translate(:"buz")
74
+ end
75
+
76
+ test "returns an array of translations 2" do
77
+ assert_equal [Globalize::Translation::Static], I18n.translate(:"buz").values.map(&:class)
78
+ end
79
+
80
+ test "returns currency properly formated" do
81
+ currency = number_to_currency(10)
82
+ assert_equal "$10.00", currency
83
+ end
84
+
85
+ test "returns currency properly formated for locale" do
86
+ currency = number_to_currency(10, :locale => :'de')
87
+ assert_equal "10.000 €", currency
88
+ end
89
+
90
+ test "returns currency properly formated from parameters" do
91
+ currency = number_to_currency(10, :format => "%n %u", :unit => '€')
92
+ assert_equal "10.00 €", currency
93
+ end
94
+
95
+ # test "makes sure interpolation does not break even with False as string" do
96
+ # result = ''
97
+ # assert_nothing_raised do
98
+ # result = I18n.t(:missing, :default => "{{value}}", :value => false)
99
+ # end
100
+ # assert_equal "false", result
101
+ # end
102
+ end
103
+
104
+ class TranslationStaticTest < ActiveSupport::TestCase
105
+ def setup
106
+ I18n.backend = Globalize::Backend::Static.new
107
+ translations = {
108
+ :greeting => "Hi {{name}}",
109
+ :messages => { :one => "You have one message.", :other => "You have {{count}} messages."}
110
+ }
111
+ I18n.backend.store_translations :"en", translations
112
+ end
113
+
114
+ def greeting
115
+ I18n.translate :greeting, :locale => :"en-US", :name => "Joshua"
116
+ end
117
+
118
+ test "stores the actual locale" do
119
+ assert_equal :en, greeting.locale
120
+ end
121
+
122
+ test "stores the requested locale" do
123
+ assert_equal :'en-US', greeting.requested_locale
124
+ end
125
+
126
+ test "stores the requested key" do
127
+ assert_equal :greeting, greeting.key
128
+ end
129
+
130
+ test "stores the options given to #translate" do
131
+ assert_equal( {:name => "Joshua"}, greeting.options )
132
+ end
133
+
134
+ test "stores the original translation before test was interpolated" do
135
+ assert_equal "Hi {{name}}", greeting.original
136
+ end
137
+
138
+ test "stores the plural_key :one if pluralized as such" do
139
+ message = I18n.translate :messages, :locale => :"en-US", :count => 1
140
+ assert_equal :one, message.plural_key
141
+ end
142
+
143
+ test "stores the plural_key :other if pluralized as such" do
144
+ messages = I18n.translate :messages, :locale => :"en-US", :count => 2
145
+ assert_equal :other, messages.plural_key
146
+ end
147
+ end
@@ -0,0 +1,2 @@
1
+ en-US:
2
+ from-all-file: From the "all" file.
@@ -0,0 +1,2 @@
1
+ de-DE:
2
+ from-locale-file: Aus der Locale Datei.
@@ -0,0 +1,2 @@
1
+ en-US:
2
+ from-locale-file: From the locale file.
@@ -0,0 +1,2 @@
1
+ en-US:
2
+ from-locale-dir: From the locale directory.
@@ -0,0 +1,2 @@
1
+ fi-FI:
2
+ from-locale-dir: Locale hakemistosta.
File without changes
@@ -0,0 +1,40 @@
1
+ class PostTranslation < ActiveRecord::Base
2
+ def existing_method ; end
3
+ end
4
+ class Post < ActiveRecord::Base
5
+ translates :subject, :content
6
+ validates_presence_of :subject
7
+ end
8
+
9
+ class Blog < ActiveRecord::Base
10
+ has_many :posts, :order => 'id ASC'
11
+ end
12
+
13
+ class Parent < ActiveRecord::Base
14
+ translates :content
15
+ end
16
+
17
+ class Child < Parent
18
+ end
19
+
20
+ class Comment < ActiveRecord::Base
21
+ validates_presence_of :content
22
+ belongs_to :post
23
+ end
24
+
25
+ class TranslatedComment < Comment
26
+ translates :content
27
+ end
28
+
29
+ class UltraLongModelNameWithoutProper < ActiveRecord::Base
30
+ translates :subject, :content
31
+ validates_presence_of :subject
32
+ end
33
+
34
+ class Reloader < Parent
35
+ after_create :do_reload
36
+
37
+ def do_reload
38
+ reload
39
+ end
40
+ end
@@ -0,0 +1,11 @@
1
+ # This schema creates tables without columns for the translated fields
2
+ ActiveRecord::Schema.define do
3
+ create_table :blogs, :force => true do |t|
4
+ t.string :name
5
+ end
6
+
7
+ create_table :posts, :force => true do |t|
8
+ t.references :blog
9
+ end
10
+ end
11
+
@@ -0,0 +1,39 @@
1
+ ActiveRecord::Schema.define do
2
+
3
+ create_table :blogs, :force => true do |t|
4
+ t.string :description
5
+ end
6
+
7
+ create_table :posts, :force => true do |t|
8
+ t.references :blog
9
+ end
10
+
11
+ create_table :post_translations, :force => true do |t|
12
+ t.string :locale
13
+ t.references :post
14
+ t.string :subject
15
+ t.text :content
16
+ end
17
+
18
+ create_table :parents, :force => true do |t|
19
+ end
20
+
21
+ create_table :parent_translations, :force => true do |t|
22
+ t.string :locale
23
+ t.references :parent
24
+ t.text :content
25
+ t.string :type
26
+ end
27
+
28
+ create_table :comments, :force => true do |t|
29
+ t.references :post
30
+ end
31
+
32
+ create_table :translated_comment_translations, :force => true do |t|
33
+ t.string :locale
34
+ t.references :comment
35
+ t.string :subject
36
+ t.text :content
37
+ end
38
+
39
+ end
@@ -0,0 +1,36 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'test_helper' )
2
+ require 'globalize/i18n/missing_translations_log_handler'
3
+
4
+ class MissingTranslationsTest < ActiveSupport::TestCase
5
+ test "defines I18n.missing_translations_logger accessor" do
6
+ assert I18n.respond_to?(:missing_translations_logger)
7
+ end
8
+
9
+ test "defines I18n.missing_translations_logger= writer" do
10
+ assert I18n.respond_to?(:missing_translations_logger=)
11
+ end
12
+ end
13
+
14
+ class TestLogger < String
15
+ def warn(msg) self.concat msg; end
16
+ end
17
+
18
+ class LogMissingTranslationsTest < ActiveSupport::TestCase
19
+ def setup
20
+ @locale, @key, @options = :en, :foo, {}
21
+ @exception = I18n::MissingTranslationData.new(@locale, @key, @options)
22
+
23
+ @logger = TestLogger.new
24
+ I18n.missing_translations_logger = @logger
25
+ end
26
+
27
+ test "still returns the exception message for MissingTranslationData exceptions" do
28
+ result = I18n.send(:missing_translations_log_handler, @exception, @locale, @key, @options)
29
+ assert_equal 'translation missing: en, foo', result
30
+ end
31
+
32
+ test "logs the missing translation to I18n.missing_translations_logger" do
33
+ I18n.send(:missing_translations_log_handler, @exception, @locale, @key, @options)
34
+ assert_equal 'translation missing: en, foo', @logger
35
+ end
36
+ end
@@ -0,0 +1,49 @@
1
+ require File.join( File.dirname(__FILE__), 'test_helper' )
2
+ require 'globalize/load_path'
3
+
4
+ class LoadPathTest < ActiveSupport::TestCase
5
+ def setup
6
+ @plugin_dir = "#{File.dirname(__FILE__)}/.."
7
+ @locale_dir = "#{File.dirname(__FILE__)}/data/locale"
8
+ @load_path = Globalize::LoadPath.new
9
+ end
10
+
11
+ test "returns glob patterns for all locales and ruby + yaml files by default" do
12
+ patterns = %w(locales/all.rb
13
+ locales/*.rb
14
+ locales/*/**/*.rb
15
+ locales/all.yml
16
+ locales/*.yml
17
+ locales/*/**/*.yml)
18
+ assert_equal patterns, @load_path.send(:patterns, 'locales')
19
+ end
20
+
21
+ test "returns the glob patterns for registered locales and extensions" do
22
+ @load_path.locales = [:en, :de]
23
+ @load_path.extensions = [:sql]
24
+ patterns = %w(locales/all.sql
25
+ locales/en.sql
26
+ locales/en/**/*.sql
27
+ locales/de.sql
28
+ locales/de/**/*.sql)
29
+ assert_equal patterns, @load_path.send(:patterns, 'locales')
30
+ end
31
+
32
+ test "expands paths using yml as a default file extension" do
33
+ @load_path << @locale_dir
34
+ expected = %w(all.yml de-DE.yml en-US.yml en-US/module.yml fi-FI/module.yml root.yml)
35
+ assert_equal expected, @load_path.map{|path| path.sub("#{@locale_dir}\/", '')}
36
+ end
37
+
38
+ test "appends new paths to the collection so earlier collected paths preceed later collected ones" do
39
+ @load_path.locales = [:root]
40
+ @load_path << "#{@plugin_dir}/lib/locale"
41
+ @load_path << @locale_dir
42
+
43
+ expected = %W(#{@plugin_dir}/lib/locale/root.yml
44
+ #{@locale_dir}/all.yml
45
+ #{@locale_dir}/root.yml)
46
+ assert_equal expected, @load_path
47
+ end
48
+
49
+ end
@@ -0,0 +1,154 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'test_helper' )
2
+ require 'globalize/locale/fallbacks'
3
+
4
+ include Globalize::Locale
5
+ I18n.default_locale = :'en-US' # This has to be set explicitly, no longer default for I18n
6
+
7
+ class FallbacksTest < ActiveSupport::TestCase
8
+ def setup
9
+ I18n.fallbacks = Fallbacks.new
10
+ end
11
+
12
+ def teardown
13
+ I18n.default_locale = :'en-US'
14
+ end
15
+
16
+ test "#[] caches computed results" do
17
+ I18n.fallbacks['en']
18
+ assert_equal( { :en => [:en, :"en-US", :root] }, I18n.fallbacks )
19
+ end
20
+
21
+ test "#defaults always reflect the I18n.default_locale if no default has been set manually" do
22
+ I18n.default_locale = :'en-US'
23
+ assert_equal( [:'en-US', :en, :root], I18n.fallbacks.defaults )
24
+ end
25
+
26
+ test "#defaults always reflect a manually passed default locale if any" do
27
+ I18n.fallbacks = Fallbacks.new(:'fi-FI')
28
+ assert_equal( [:'fi-FI', :fi, :root], I18n.fallbacks.defaults )
29
+ I18n.default_locale = :'de-DE'
30
+ assert_equal( [:'fi-FI', :fi, :root], I18n.fallbacks.defaults )
31
+ end
32
+
33
+ test "#defaults allows to set multiple defaults" do
34
+ I18n.fallbacks = Fallbacks.new(:'fi-FI', :'se-FI')
35
+ assert_equal( [:'fi-FI', :fi, :'se-FI', :se, :root], I18n.fallbacks.defaults )
36
+ end
37
+ end
38
+
39
+ class NoMappingFallbacksTest < ActiveSupport::TestCase
40
+ def setup
41
+ @fallbacks = Fallbacks.new(:'en-US')
42
+ end
43
+
44
+ test "returns [:es, :en-US, :root] for :es" do
45
+ assert_equal [:es, :"en-US", :en, :root], @fallbacks[:es]
46
+ end
47
+
48
+ test "returns [:es-ES, :es, :en-US, :root] for :es-ES" do
49
+ assert_equal [:"es-ES", :es, :"en-US", :en, :root], @fallbacks[:"es-ES"]
50
+ end
51
+
52
+ test "returns [:es-MX, :es, :en-US, :root] for :es-MX" do
53
+ assert_equal [:"es-MX", :es, :"en-US", :en, :root], @fallbacks[:"es-MX"]
54
+ end
55
+
56
+ test "returns [:es-Latn-ES, :es-Latn, :es, :en-US, :root] for :es-Latn-ES" do
57
+ assert_equal [:"es-Latn-ES", :"es-Latn", :es, :"en-US", :en, :root], @fallbacks[:'es-Latn-ES']
58
+ end
59
+
60
+ test "returns [:en, :en-US, :root] for :en" do
61
+ assert_equal [:en, :"en-US", :root], @fallbacks[:en]
62
+ end
63
+
64
+ test "returns [:en-US, :en, :root] for :en-US (special case: locale == default)" do
65
+ assert_equal [:"en-US", :en, :root], @fallbacks[:"en-US"]
66
+ end
67
+ end
68
+
69
+ class CaMappingFallbacksTest < ActiveSupport::TestCase
70
+ # Most people who speak Catalan also live in Spain, so test is safe to assume
71
+ # that they also speak Spanish as spoken in Spain.
72
+ def setup
73
+ @fallbacks = Fallbacks.new(:'en-US')
74
+ @fallbacks.map :ca => :"es-ES"
75
+ end
76
+
77
+ test "returns [:ca, :es-ES, :es, :en-US, :root] for :ca" do
78
+ assert_equal [:ca, :"es-ES", :es, :"en-US", :en, :root], @fallbacks[:ca]
79
+ end
80
+
81
+ test "returns [:ca-ES, :ca, :es-ES, :es, :en-US, :root] for :ca-ES" do
82
+ assert_equal [:"ca-ES", :ca, :"es-ES", :es, :"en-US", :en, :root], @fallbacks[:"ca-ES"]
83
+ end
84
+ end
85
+
86
+ class ArMappingFallbacksTest < ActiveSupport::TestCase
87
+ # People who speak Arabic as spoken in Palestine often times also speak
88
+ # Hebrew as spoken in Israel. However test is in no way safe to assume that
89
+ # everybody who speaks Arabic also speaks Hebrew.
90
+ def setup
91
+ @fallbacks = Fallbacks.new(:'en-US')
92
+ @fallbacks.map :"ar-PS" => :"he-IL"
93
+ end
94
+
95
+ test "returns [:ar, :en-US, :root] for :ar" do
96
+ assert_equal [:ar, :"en-US", :en, :root], @fallbacks[:ar]
97
+ end
98
+
99
+ test "returns [:ar-EG, :ar, :en-US, :root] for :ar-EG" do
100
+ assert_equal [:"ar-EG", :ar, :"en-US", :en, :root], @fallbacks[:"ar-EG"]
101
+ end
102
+
103
+ test "returns [:ar-PS, :ar, :he-IL, :he, :en-US, :root] for :ar-PS" do
104
+ assert_equal [:"ar-PS", :ar, :"he-IL", :he, :"en-US", :en, :root], @fallbacks[:"ar-PS"]
105
+ end
106
+ end
107
+
108
+ class SmsMappingFallbacksTest < ActiveSupport::TestCase
109
+ # Sami people live in several scandinavian countries. In Finnland many people
110
+ # know Swedish and Finnish. Thus, test can be assumed that Sami living in
111
+ # Finnland also speak Swedish and Finnish.
112
+ def setup
113
+ @fallbacks = Fallbacks.new(:'en-US')
114
+ @fallbacks.map :sms => [:"se-FI", :"fi-FI"]
115
+ end
116
+
117
+ test "returns [:sms-FI, :sms, :se-FI, :se, :fi-FI, :fi, :en-US, :root] for :sms-FI" do
118
+ assert_equal [:"sms-FI", :sms, :"se-FI", :se, :"fi-FI", :fi, :"en-US", :en, :root], @fallbacks[:"sms-FI"]
119
+ end
120
+ end
121
+
122
+ class DeAtMappingFallbacksTest < ActiveSupport::TestCase
123
+ def setup
124
+ @fallbacks = Fallbacks.new(:'en-US')
125
+ @fallbacks.map :"de-AT" => :"de-DE"
126
+ end
127
+
128
+ test "returns [:de, :en-US, :root] for de" do
129
+ assert_equal [:de, :"en-US", :en, :root], @fallbacks[:"de"]
130
+ end
131
+
132
+ test "returns [:de-DE, :de, :en-US, :root] for de-DE" do
133
+ assert_equal [:"de-DE", :de, :"en-US", :en, :root], @fallbacks[:"de-DE"]
134
+ end
135
+
136
+ test "returns [:de-AT, :de, :de-DE, :en-US, :root] for de-AT" do
137
+ assert_equal [:"de-AT", :de, :"de-DE", :"en-US", :en, :root], @fallbacks[:"de-AT"]
138
+ end
139
+ end
140
+
141
+ class DeMappingFallbacksTest < ActiveSupport::TestCase
142
+ def setup
143
+ @fallbacks = Fallbacks.new(:'en-US')
144
+ @fallbacks.map :de => :en, :he => :en
145
+ end
146
+
147
+ test "returns [:de, :en, :root] for :de" do
148
+ assert_equal [:de, :en, :"en-US", :root], @fallbacks[:de]
149
+ end
150
+
151
+ test "returns [:he, :en, :root] for :de" do
152
+ assert_equal [:he, :en, :"en-US", :root], @fallbacks[:he]
153
+ end
154
+ end