diff options
| author | hukl <contact@smyck.org> | 2010-01-14 22:21:43 +0100 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2010-01-14 22:21:43 +0100 |
| commit | 57d1382013c85a7b11ac8ce5e683f6006b12b328 (patch) | |
| tree | 19646c4fa5952fa1cf0a2c874952affa346373f1 /vendor/plugins/globalize2/test/backends/static_test.rb | |
| parent | 1b86bf5f2e35d1820bfa32d979bcc2d9ff9a9a8e (diff) | |
Updated globalize2 to latest version. Modified existing code accoringly
Diffstat (limited to 'vendor/plugins/globalize2/test/backends/static_test.rb')
| -rw-r--r-- | vendor/plugins/globalize2/test/backends/static_test.rb | 143 |
1 files changed, 0 insertions, 143 deletions
diff --git a/vendor/plugins/globalize2/test/backends/static_test.rb b/vendor/plugins/globalize2/test/backends/static_test.rb deleted file mode 100644 index 133e5477..00000000 --- a/vendor/plugins/globalize2/test/backends/static_test.rb +++ /dev/null | |||
| @@ -1,143 +0,0 @@ | |||
| 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"}, | ||
| 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 | assert_equal "translation missing: en, support, array, skip_last_comma", I18n.translate(:"support.array.skip_last_comma") | ||
| 97 | end | ||
| 98 | end | ||
| 99 | |||
| 100 | class TranslationStaticTest < ActiveSupport::TestCase | ||
| 101 | def setup | ||
| 102 | I18n.backend = Globalize::Backend::Static.new | ||
| 103 | translations = { | ||
| 104 | :greeting => "Hi {{name}}", | ||
| 105 | :messages => { :one => "You have one message.", :other => "You have {{count}} messages."} | ||
| 106 | } | ||
| 107 | I18n.backend.store_translations :"en", translations | ||
| 108 | end | ||
| 109 | |||
| 110 | def greeting | ||
| 111 | I18n.translate :greeting, :locale => :"en-US", :name => "Joshua" | ||
| 112 | end | ||
| 113 | |||
| 114 | test "stores the actual locale" do | ||
| 115 | assert_equal :en, greeting.locale | ||
| 116 | end | ||
| 117 | |||
| 118 | test "stores the requested locale" do | ||
| 119 | assert_equal :'en-US', greeting.requested_locale | ||
| 120 | end | ||
| 121 | |||
| 122 | test "stores the requested key" do | ||
| 123 | assert_equal :greeting, greeting.key | ||
| 124 | end | ||
| 125 | |||
| 126 | test "stores the options given to #translate" do | ||
| 127 | assert_equal( {:name => "Joshua"}, greeting.options ) | ||
| 128 | end | ||
| 129 | |||
| 130 | test "stores the original translation before test was interpolated" do | ||
| 131 | assert_equal "Hi {{name}}", greeting.original | ||
| 132 | end | ||
| 133 | |||
| 134 | test "stores the plural_key :one if pluralized as such" do | ||
| 135 | message = I18n.translate :messages, :locale => :"en-US", :count => 1 | ||
| 136 | assert_equal :one, message.plural_key | ||
| 137 | end | ||
| 138 | |||
| 139 | test "stores the plural_key :other if pluralized as such" do | ||
| 140 | messages = I18n.translate :messages, :locale => :"en-US", :count => 2 | ||
| 141 | assert_equal :other, messages.plural_key | ||
| 142 | end | ||
| 143 | end | ||
