diff options
| author | hukl <hukl@eight.local> | 2009-02-07 15:50:40 +0100 |
|---|---|---|
| committer | hukl <hukl@eight.local> | 2009-02-07 15:50:40 +0100 |
| commit | 36a2f1f3c085dd81171cf7d8220770d4ff921ab3 (patch) | |
| tree | 5ded15331b192bf428af4c94d46d1abb28ef0690 /vendor/plugins/globalize2/test | |
| parent | ce9645d0092d42c7bf8781378181ffbd4ff3d088 (diff) | |
added globalize2 plugin as well as some modifications
which use the new translation facilities.
backend mostly.
Diffstat (limited to 'vendor/plugins/globalize2/test')
19 files changed, 1197 insertions, 0 deletions
diff --git a/vendor/plugins/globalize2/test/backends/chained_test.rb b/vendor/plugins/globalize2/test/backends/chained_test.rb new file mode 100644 index 0000000..bc45179 --- /dev/null +++ b/vendor/plugins/globalize2/test/backends/chained_test.rb | |||
| @@ -0,0 +1,174 @@ | |||
| 1 | require File.join( File.dirname(__FILE__), '..', 'test_helper' ) | ||
| 2 | require 'globalize/backend/chain' | ||
| 3 | |||
| 4 | module Globalize | ||
| 5 | module Backend | ||
| 6 | class Dummy | ||
| 7 | def translate(locale, key, options = {}) | ||
| 8 | end | ||
| 9 | end | ||
| 10 | end | ||
| 11 | end | ||
| 12 | |||
| 13 | class ChainedTest < ActiveSupport::TestCase | ||
| 14 | |||
| 15 | test "instantiates a chained backend and sets test as backend" do | ||
| 16 | assert_nothing_raised { I18n.chain_backends } | ||
| 17 | assert_instance_of Globalize::Backend::Chain, I18n.backend | ||
| 18 | end | ||
| 19 | |||
| 20 | test "passes all given arguments to the chained backends #initialize method" do | ||
| 21 | Globalize::Backend::Chain.expects(:new).with(:spec, :simple) | ||
| 22 | I18n.chain_backends :spec, :simple | ||
| 23 | end | ||
| 24 | |||
| 25 | test "passes all given arguments to #add assuming that they are backends" do | ||
| 26 | # no idea how to spec that | ||
| 27 | end | ||
| 28 | end | ||
| 29 | |||
| 30 | class AddChainedTest < ActiveSupport::TestCase | ||
| 31 | def setup | ||
| 32 | I18n.backend = Globalize::Backend::Chain.new | ||
| 33 | end | ||
| 34 | |||
| 35 | test "accepts an instance of a backend" do | ||
| 36 | assert_nothing_raised { I18n.backend.add Globalize::Backend::Dummy.new } | ||
| 37 | assert_instance_of Globalize::Backend::Dummy, I18n.backend.send(:backends).first | ||
| 38 | end | ||
| 39 | |||
| 40 | test "accepts a class and instantiates the backend" do | ||
| 41 | assert_nothing_raised { I18n.backend.add Globalize::Backend::Dummy } | ||
| 42 | assert_instance_of Globalize::Backend::Dummy, I18n.backend.send(:backends).first | ||
| 43 | end | ||
| 44 | |||
| 45 | test "accepts a symbol, constantizes test as a backend class and instantiates the backend" do | ||
| 46 | assert_nothing_raised { I18n.backend.add :dummy } | ||
| 47 | assert_instance_of Globalize::Backend::Dummy, I18n.backend.send(:backends).first | ||
| 48 | end | ||
| 49 | |||
| 50 | test "accepts any number of backend instances, classes or symbols" do | ||
| 51 | assert_nothing_raised { I18n.backend.add Globalize::Backend::Dummy.new, Globalize::Backend::Dummy, :dummy } | ||
| 52 | assert_instance_of Globalize::Backend::Dummy, I18n.backend.send(:backends).first | ||
| 53 | assert_equal [ Globalize::Backend::Dummy, Globalize::Backend::Dummy, Globalize::Backend::Dummy ], | ||
| 54 | I18n.backend.send(:backends).map{|backend| backend.class } | ||
| 55 | end | ||
| 56 | |||
| 57 | end | ||
| 58 | |||
| 59 | class TranslateChainedTest < ActiveSupport::TestCase | ||
| 60 | def setup | ||
| 61 | I18n.backend = Globalize::Backend::Chain.new | ||
| 62 | @first_backend = I18n::Backend::Simple.new | ||
| 63 | @last_backend = I18n::Backend::Simple.new | ||
| 64 | I18n.backend.add @first_backend | ||
| 65 | I18n.backend.add @last_backend | ||
| 66 | end | ||
| 67 | |||
| 68 | test "delegates #translate to all backends in the order they were added" do | ||
| 69 | @first_backend.expects(:translate).with(:en, :foo, {}) | ||
| 70 | @last_backend.expects(:translate).with(:en, :foo, {}) | ||
| 71 | I18n.translate :foo | ||
| 72 | end | ||
| 73 | |||
| 74 | test "returns the result from #translate from the first backend if test's not nil" do | ||
| 75 | @first_backend.store_translations :en, {:foo => 'foo from first backend'} | ||
| 76 | @last_backend.store_translations :en, {:foo => 'foo from last backend'} | ||
| 77 | result = I18n.translate :foo | ||
| 78 | assert_equal 'foo from first backend', result | ||
| 79 | end | ||
| 80 | |||
| 81 | test "returns the result from #translate from the second backend if the first one returned nil" do | ||
| 82 | @first_backend.store_translations :en, {} | ||
| 83 | @last_backend.store_translations :en, {:foo => 'foo from last backend'} | ||
| 84 | result = I18n.translate :foo | ||
| 85 | assert_equal 'foo from last backend', result | ||
| 86 | end | ||
| 87 | |||
| 88 | test "looks up a namespace from all backends and merges them (if a result is a hash and no count option is present)" do | ||
| 89 | @first_backend.store_translations :en, {:foo => {:bar => 'bar from first backend'}} | ||
| 90 | @last_backend.store_translations :en, {:foo => {:baz => 'baz from last backend'}} | ||
| 91 | result = I18n.translate :foo | ||
| 92 | assert_equal( {:bar => 'bar from first backend', :baz => 'baz from last backend'}, result ) | ||
| 93 | end | ||
| 94 | |||
| 95 | test "raises a MissingTranslationData exception if no translation was found" do | ||
| 96 | assert_raise( I18n::MissingTranslationData ) { I18n.translate :not_here, :raise => true } | ||
| 97 | end | ||
| 98 | |||
| 99 | test "raises an InvalidLocale exception if the locale is nil" do | ||
| 100 | assert_raise( I18n::InvalidLocale ) { Globalize::Backend::Chain.new.translate nil, :foo } | ||
| 101 | end | ||
| 102 | |||
| 103 | test "bulk translates a number of keys from different backends" do | ||
| 104 | @first_backend.store_translations :en, {:foo => 'foo from first backend'} | ||
| 105 | @last_backend.store_translations :en, {:bar => 'bar from last backend'} | ||
| 106 | result = I18n.translate [:foo, :bar] | ||
| 107 | assert_equal( ['foo from first backend', 'bar from last backend'], result ) | ||
| 108 | end | ||
| 109 | |||
| 110 | test "still calls #translate on all the backends" do | ||
| 111 | @last_backend.expects :translate | ||
| 112 | I18n.translate :not_here, :default => 'default' | ||
| 113 | end | ||
| 114 | |||
| 115 | test "returns a given default string when no backend returns a translation" do | ||
| 116 | result = I18n.translate :not_here, :default => 'default' | ||
| 117 | assert_equal 'default', result | ||
| 118 | end | ||
| 119 | |||
| 120 | end | ||
| 121 | |||
| 122 | class CustomLocalizeBackend < I18n::Backend::Simple | ||
| 123 | def localize(locale, object, format = :default) | ||
| 124 | "result from custom localize backend" if locale == 'custom' | ||
| 125 | end | ||
| 126 | end | ||
| 127 | |||
| 128 | class LocalizeChainedTest < ActiveSupport::TestCase | ||
| 129 | def setup | ||
| 130 | I18n.locale = :en | ||
| 131 | I18n.backend = Globalize::Backend::Chain.new | ||
| 132 | @first_backend = CustomLocalizeBackend.new | ||
| 133 | @last_backend = I18n::Backend::Simple.new | ||
| 134 | I18n.backend.add @first_backend | ||
| 135 | I18n.backend.add @last_backend | ||
| 136 | @time = Time.now | ||
| 137 | end | ||
| 138 | |||
| 139 | test "delegates #localize to all backends in the order they were added" do | ||
| 140 | @first_backend.expects(:localize).with(:en, @time, :default) | ||
| 141 | @last_backend.expects(:localize).with(:en, @time, :default) | ||
| 142 | I18n.localize @time | ||
| 143 | end | ||
| 144 | |||
| 145 | test "returns the result from #localize from the first backend if test's not nil" do | ||
| 146 | @last_backend.expects(:localize).never | ||
| 147 | result = I18n.localize @time, :locale => 'custom' | ||
| 148 | assert_equal 'result from custom localize backend', result | ||
| 149 | end | ||
| 150 | |||
| 151 | test "returns the result from #localize from the second backend if the first one returned nil" do | ||
| 152 | @last_backend.expects(:localize).returns "value from last backend" | ||
| 153 | result = I18n.localize @time | ||
| 154 | assert_equal 'value from last backend', result | ||
| 155 | end | ||
| 156 | end | ||
| 157 | |||
| 158 | class NamespaceChainedTest < ActiveSupport::TestCase | ||
| 159 | def setup | ||
| 160 | @backend = Globalize::Backend::Chain.new | ||
| 161 | end | ||
| 162 | |||
| 163 | test "returns false if the given result is not a Hash" do | ||
| 164 | assert !@backend.send(:namespace_lookup?, 'foo', {}) | ||
| 165 | end | ||
| 166 | |||
| 167 | test "returns false if a count option is present" do | ||
| 168 | assert !@backend.send(:namespace_lookup?, {:foo => 'foo'}, {:count => 1}) | ||
| 169 | end | ||
| 170 | |||
| 171 | test "returns true if the given result is a Hash AND no count option is present" do | ||
| 172 | assert @backend.send(:namespace_lookup?, {:foo => 'foo'}, {}) | ||
| 173 | end | ||
| 174 | end | ||
diff --git a/vendor/plugins/globalize2/test/backends/pluralizing_test.rb b/vendor/plugins/globalize2/test/backends/pluralizing_test.rb new file mode 100644 index 0000000..7445e3f --- /dev/null +++ b/vendor/plugins/globalize2/test/backends/pluralizing_test.rb | |||
| @@ -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 | ||
diff --git a/vendor/plugins/globalize2/test/backends/static_test.rb b/vendor/plugins/globalize2/test/backends/static_test.rb new file mode 100644 index 0000000..133e547 --- /dev/null +++ b/vendor/plugins/globalize2/test/backends/static_test.rb | |||
| @@ -0,0 +1,143 @@ | |||
| 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 | ||
diff --git a/vendor/plugins/globalize2/test/data/locale/all.yml b/vendor/plugins/globalize2/test/data/locale/all.yml new file mode 100644 index 0000000..ee4fb4a --- /dev/null +++ b/vendor/plugins/globalize2/test/data/locale/all.yml | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | en-US: | ||
| 2 | from-all-file: From the "all" file. | ||
diff --git a/vendor/plugins/globalize2/test/data/locale/de-DE.yml b/vendor/plugins/globalize2/test/data/locale/de-DE.yml new file mode 100644 index 0000000..d4c468e --- /dev/null +++ b/vendor/plugins/globalize2/test/data/locale/de-DE.yml | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | de-DE: | ||
| 2 | from-locale-file: Aus der Locale Datei. \ No newline at end of file | ||
diff --git a/vendor/plugins/globalize2/test/data/locale/en-US.yml b/vendor/plugins/globalize2/test/data/locale/en-US.yml new file mode 100644 index 0000000..866b171 --- /dev/null +++ b/vendor/plugins/globalize2/test/data/locale/en-US.yml | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | en-US: | ||
| 2 | from-locale-file: From the locale file. | ||
diff --git a/vendor/plugins/globalize2/test/data/locale/en-US/module.yml b/vendor/plugins/globalize2/test/data/locale/en-US/module.yml new file mode 100644 index 0000000..6655e9b --- /dev/null +++ b/vendor/plugins/globalize2/test/data/locale/en-US/module.yml | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | en-US: | ||
| 2 | from-locale-dir: From the locale directory. | ||
diff --git a/vendor/plugins/globalize2/test/data/locale/fi-FI/module.yml b/vendor/plugins/globalize2/test/data/locale/fi-FI/module.yml new file mode 100644 index 0000000..62d00b1 --- /dev/null +++ b/vendor/plugins/globalize2/test/data/locale/fi-FI/module.yml | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | fi-FI: | ||
| 2 | from-locale-dir: Locale hakemistosta. \ No newline at end of file | ||
diff --git a/vendor/plugins/globalize2/test/data/locale/root.yml b/vendor/plugins/globalize2/test/data/locale/root.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vendor/plugins/globalize2/test/data/locale/root.yml | |||
diff --git a/vendor/plugins/globalize2/test/data/no_globalize_schema.rb b/vendor/plugins/globalize2/test/data/no_globalize_schema.rb new file mode 100644 index 0000000..7cfaf69 --- /dev/null +++ b/vendor/plugins/globalize2/test/data/no_globalize_schema.rb | |||
| @@ -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 | |||
diff --git a/vendor/plugins/globalize2/test/data/post.rb b/vendor/plugins/globalize2/test/data/post.rb new file mode 100644 index 0000000..20a2495 --- /dev/null +++ b/vendor/plugins/globalize2/test/data/post.rb | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | class Post < ActiveRecord::Base | ||
| 2 | translates :subject, :content | ||
| 3 | validates_presence_of :subject | ||
| 4 | end | ||
| 5 | |||
| 6 | class Blog < ActiveRecord::Base | ||
| 7 | has_many :posts, :order => 'id ASC' | ||
| 8 | end | ||
diff --git a/vendor/plugins/globalize2/test/i18n/missing_translations_test.rb b/vendor/plugins/globalize2/test/i18n/missing_translations_test.rb new file mode 100644 index 0000000..8641d57 --- /dev/null +++ b/vendor/plugins/globalize2/test/i18n/missing_translations_test.rb | |||
| @@ -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 | ||
diff --git a/vendor/plugins/globalize2/test/load_path_test.rb b/vendor/plugins/globalize2/test/load_path_test.rb new file mode 100644 index 0000000..ff009b3 --- /dev/null +++ b/vendor/plugins/globalize2/test/load_path_test.rb | |||
| @@ -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 | ||
diff --git a/vendor/plugins/globalize2/test/locale/fallbacks_test.rb b/vendor/plugins/globalize2/test/locale/fallbacks_test.rb new file mode 100644 index 0000000..304d3da --- /dev/null +++ b/vendor/plugins/globalize2/test/locale/fallbacks_test.rb | |||
| @@ -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 | ||
diff --git a/vendor/plugins/globalize2/test/locale/language_tag_test.rb b/vendor/plugins/globalize2/test/locale/language_tag_test.rb new file mode 100644 index 0000000..2448af1 --- /dev/null +++ b/vendor/plugins/globalize2/test/locale/language_tag_test.rb | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | require File.join( File.dirname(__FILE__), '..', 'test_helper' ) | ||
| 2 | require 'globalize/locale/language_tag' | ||
| 3 | |||
| 4 | include Globalize::Locale | ||
| 5 | |||
| 6 | class LanguageTagTest < ActiveSupport::TestCase | ||
| 7 | test "given a valid tag 'de' returns an LanguageTag from #tag" do | ||
| 8 | assert_instance_of LanguageTag, LanguageTag.tag('de') | ||
| 9 | end | ||
| 10 | |||
| 11 | test "given a valid tag 'de' returns an array of subtags" do | ||
| 12 | assert_equal ['de', nil, nil, nil, nil, nil, nil], LanguageTag::SimpleParser.match('de') | ||
| 13 | end | ||
| 14 | |||
| 15 | test "given a valid tag 'de-DE' returns an array of subtags" do | ||
| 16 | assert_equal ['de', nil, 'DE', nil, nil, nil, nil], LanguageTag::SimpleParser.match('de-DE') | ||
| 17 | end | ||
| 18 | |||
| 19 | test "given a valid lowercase tag 'de-latn-de-variant-x-phonebk' returns an array of subtags" do | ||
| 20 | assert_equal ['de', 'latn', 'de', 'variant', nil, 'x-phonebk', nil], | ||
| 21 | LanguageTag::SimpleParser.match('de-latn-de-variant-x-phonebk') | ||
| 22 | end | ||
| 23 | |||
| 24 | test "given a valid uppercase tag 'DE-LATN-DE-VARIANT-X-PHONEBK' returns an array of subtags" do | ||
| 25 | assert_equal ['DE', 'LATN', 'DE', 'VARIANT', nil, 'X-PHONEBK', nil], | ||
| 26 | LanguageTag::SimpleParser.match('DE-LATN-DE-VARIANT-X-PHONEBK') | ||
| 27 | end | ||
| 28 | |||
| 29 | test "given an invalid tag 'a-DE' test returns false" do | ||
| 30 | assert !LanguageTag::SimpleParser.match('a-DE') | ||
| 31 | end | ||
| 32 | |||
| 33 | test "given an invalid tag 'de-419-DE' test returns false" do | ||
| 34 | assert !LanguageTag::SimpleParser.match('de-419-DE') | ||
| 35 | end | ||
| 36 | end | ||
| 37 | |||
| 38 | class DeLatnLanguageTagTest < ActiveSupport::TestCase | ||
| 39 | def setup | ||
| 40 | subtags = %w(de Latn DE variant a-ext x-phonebk i-klingon) | ||
| 41 | @tag = LanguageTag.new *subtags | ||
| 42 | end | ||
| 43 | |||
| 44 | test "returns 'de' as the language subtag in lowercase" do | ||
| 45 | assert_equal 'de', @tag.language | ||
| 46 | end | ||
| 47 | |||
| 48 | test "returns 'Latn' as the script subtag in titlecase" do | ||
| 49 | assert_equal 'Latn', @tag.script | ||
| 50 | end | ||
| 51 | |||
| 52 | test "returns 'DE' as the region subtag in uppercase" do | ||
| 53 | assert_equal 'DE', @tag.region | ||
| 54 | end | ||
| 55 | |||
| 56 | test "returns 'variant' as the variant subtag in lowercase" do | ||
| 57 | assert_equal 'variant', @tag.variant | ||
| 58 | end | ||
| 59 | |||
| 60 | test "returns 'a-ext' as the extension subtag" do | ||
| 61 | assert_equal 'a-ext', @tag.extension | ||
| 62 | end | ||
| 63 | |||
| 64 | test "returns 'x-phonebk' as the privateuse subtag" do | ||
| 65 | assert_equal 'x-phonebk', @tag.privateuse | ||
| 66 | end | ||
| 67 | |||
| 68 | test "returns 'i-klingon' as the grandfathered subtag" do | ||
| 69 | assert_equal 'i-klingon', @tag.grandfathered | ||
| 70 | end | ||
| 71 | |||
| 72 | test "returns a formatted tag string from #to_s" do | ||
| 73 | assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon', @tag.to_s | ||
| 74 | end | ||
| 75 | |||
| 76 | test "returns an array containing the formatted subtags from #to_a" do | ||
| 77 | assert_equal %w(de Latn DE variant a-ext x-phonebk i-klingon), @tag.to_a | ||
| 78 | end | ||
| 79 | end | ||
| 80 | |||
| 81 | class InheritanceLanguageTagTest < ActiveSupport::TestCase | ||
| 82 | test "returns 'de-Latn-DE-variant-a-ext-x-phonebk' as the parent of 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do | ||
| 83 | tag = LanguageTag.new *%w(de Latn DE variant a-ext x-phonebk i-klingon) | ||
| 84 | assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk', tag.parent.to_s | ||
| 85 | end | ||
| 86 | |||
| 87 | test "returns 'de-Latn-DE-variant-a-ext' as the parent of 'de-Latn-DE-variant-a-ext-x-phonebk'" do | ||
| 88 | tag = LanguageTag.new *%w(de Latn DE variant a-ext x-phonebk) | ||
| 89 | assert_equal 'de-Latn-DE-variant-a-ext', tag.parent.to_s | ||
| 90 | end | ||
| 91 | |||
| 92 | test "returns 'de-Latn-DE-variant' as the parent of 'de-Latn-DE-variant-a-ext'" do | ||
| 93 | tag = LanguageTag.new *%w(de Latn DE variant a-ext) | ||
| 94 | assert_equal 'de-Latn-DE-variant', tag.parent.to_s | ||
| 95 | end | ||
| 96 | |||
| 97 | test "returns 'de-Latn-DE' as the parent of 'de-Latn-DE-variant'" do | ||
| 98 | tag = LanguageTag.new *%w(de Latn DE variant) | ||
| 99 | assert_equal 'de-Latn-DE', tag.parent.to_s | ||
| 100 | end | ||
| 101 | |||
| 102 | test "returns 'de-Latn' as the parent of 'de-Latn-DE'" do | ||
| 103 | tag = LanguageTag.new *%w(de Latn DE) | ||
| 104 | assert_equal 'de-Latn', tag.parent.to_s | ||
| 105 | end | ||
| 106 | |||
| 107 | test "returns 'de' as the parent of 'de-Latn'" do | ||
| 108 | tag = LanguageTag.new *%w(de Latn) | ||
| 109 | assert_equal 'de', tag.parent.to_s | ||
| 110 | end | ||
| 111 | |||
| 112 | # TODO RFC4647 says: "If no language tag matches the request, the "default" value is returned." | ||
| 113 | # where should we set the default language? | ||
| 114 | # test "returns '' as the parent of 'de'" do | ||
| 115 | # tag = LanguageTag.new *%w(de) | ||
| 116 | # assert_equal '', tag.parent.to_s | ||
| 117 | # end | ||
| 118 | |||
| 119 | test "returns an array of 5 parents for 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do | ||
| 120 | parents = %w(de-Latn-DE-variant-a-ext-x-phonebk-i-klingon | ||
| 121 | de-Latn-DE-variant-a-ext-x-phonebk | ||
| 122 | de-Latn-DE-variant-a-ext | ||
| 123 | de-Latn-DE-variant | ||
| 124 | de-Latn-DE | ||
| 125 | de-Latn | ||
| 126 | de) | ||
| 127 | tag = LanguageTag.new *%w(de Latn DE variant a-ext x-phonebk i-klingon) | ||
| 128 | assert_equal parents, tag.parents.map{|tag| tag.to_s} | ||
| 129 | end | ||
| 130 | end | ||
diff --git a/vendor/plugins/globalize2/test/model/active_record/migration_test.rb b/vendor/plugins/globalize2/test/model/active_record/migration_test.rb new file mode 100644 index 0000000..09804c7 --- /dev/null +++ b/vendor/plugins/globalize2/test/model/active_record/migration_test.rb | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | require File.join( File.dirname(__FILE__), '..', '..', 'test_helper' ) | ||
| 2 | require 'active_record' | ||
| 3 | require 'globalize/model/active_record' | ||
| 4 | |||
| 5 | # Hook up model translation | ||
| 6 | ActiveRecord::Base.send(:include, Globalize::Model::ActiveRecord::Translated) | ||
| 7 | |||
| 8 | # Load Post model | ||
| 9 | require File.join( File.dirname(__FILE__), '..', '..', 'data', 'post' ) | ||
| 10 | |||
| 11 | class MigrationTest < ActiveSupport::TestCase | ||
| 12 | def setup | ||
| 13 | reset_db! 'no_globalize_schema' | ||
| 14 | end | ||
| 15 | |||
| 16 | test 'globalize table added' do | ||
| 17 | assert !Post.connection.table_exists?( :post_translations ) | ||
| 18 | Post.create_translation_table! :subject => :string, :content => :text | ||
| 19 | assert Post.connection.table_exists?( :post_translations ) | ||
| 20 | columns = Post.connection.columns( :post_translations ) | ||
| 21 | assert locale = columns.detect {|c| c.name == 'locale' } | ||
| 22 | assert_equal :string, locale.type | ||
| 23 | assert subject = columns.detect {|c| c.name == 'subject' } | ||
| 24 | assert_equal :string, subject.type | ||
| 25 | assert content = columns.detect {|c| c.name == 'content' } | ||
| 26 | assert_equal :text, content.type | ||
| 27 | assert post_id = columns.detect {|c| c.name == 'post_id' } | ||
| 28 | assert_equal :integer, post_id.type | ||
| 29 | assert created_at = columns.detect {|c| c.name == 'created_at' } | ||
| 30 | assert_equal :datetime, created_at.type | ||
| 31 | assert updated_at = columns.detect {|c| c.name == 'updated_at' } | ||
| 32 | assert_equal :datetime, updated_at.type | ||
| 33 | end | ||
| 34 | |||
| 35 | test 'globalize table dropped' do | ||
| 36 | assert !Post.connection.table_exists?( :post_translations ) | ||
| 37 | Post.create_translation_table! :subject => :string, :content => :text | ||
| 38 | assert Post.connection.table_exists?( :post_translations ) | ||
| 39 | Post.drop_translation_table! | ||
| 40 | assert !Post.connection.table_exists?( :post_translations ) | ||
| 41 | end | ||
| 42 | |||
| 43 | test 'exception on untranslated field inputs' do | ||
| 44 | assert_raise Globalize::Model::UntranslatedMigrationField do | ||
| 45 | Post.create_translation_table! :subject => :string, :content => :text, :bogus => :string | ||
| 46 | end | ||
| 47 | end | ||
| 48 | |||
| 49 | test 'exception on missing field inputs' do | ||
| 50 | assert_raise Globalize::Model::MigrationMissingTranslatedField do | ||
| 51 | Post.create_translation_table! :content => :text | ||
| 52 | end | ||
| 53 | end | ||
| 54 | |||
| 55 | test 'exception on bad input type' do | ||
| 56 | assert_raise Globalize::Model::BadMigrationFieldType do | ||
| 57 | Post.create_translation_table! :subject => :string, :content => :integer | ||
| 58 | end | ||
| 59 | end | ||
| 60 | |||
| 61 | test 'create_translation_table! should not be called on non-translated models' do | ||
| 62 | assert_raise NoMethodError do | ||
| 63 | Blog.create_translation_table! :name => :string | ||
| 64 | end | ||
| 65 | end | ||
| 66 | |||
| 67 | test 'drop_translation_table! should not be called on non-translated models' do | ||
| 68 | assert_raise NoMethodError do | ||
| 69 | Blog.drop_translation_table! | ||
| 70 | end | ||
| 71 | end | ||
| 72 | |||
| 73 | end \ No newline at end of file | ||
diff --git a/vendor/plugins/globalize2/test/model/active_record/translated_test.rb b/vendor/plugins/globalize2/test/model/active_record/translated_test.rb new file mode 100644 index 0000000..ec507e0 --- /dev/null +++ b/vendor/plugins/globalize2/test/model/active_record/translated_test.rb | |||
| @@ -0,0 +1,266 @@ | |||
| 1 | require File.join( File.dirname(__FILE__), '..', '..', 'test_helper' ) | ||
| 2 | require 'active_record' | ||
| 3 | require 'globalize/model/active_record' | ||
| 4 | |||
| 5 | # Hook up model translation | ||
| 6 | ActiveRecord::Base.send(:include, Globalize::Model::ActiveRecord::Translated) | ||
| 7 | |||
| 8 | # Load Post model | ||
| 9 | require File.join( File.dirname(__FILE__), '..', '..', 'data', 'post' ) | ||
| 10 | |||
| 11 | class TranslatedTest < ActiveSupport::TestCase | ||
| 12 | def setup | ||
| 13 | I18n.locale = :'en-US' | ||
| 14 | I18n.fallbacks.clear | ||
| 15 | reset_db! | ||
| 16 | end | ||
| 17 | |||
| 18 | def teardown | ||
| 19 | I18n.fallbacks.clear | ||
| 20 | end | ||
| 21 | |||
| 22 | test "modifiying translated fields" do | ||
| 23 | post = Post.create :subject => 'foo' | ||
| 24 | assert_equal 'foo', post.subject | ||
| 25 | post.subject = 'bar' | ||
| 26 | assert_equal 'bar', post.subject | ||
| 27 | end | ||
| 28 | |||
| 29 | test "modifiying translated fields while switching locales" do | ||
| 30 | post = Post.create :subject => 'foo' | ||
| 31 | assert_equal 'foo', post.subject | ||
| 32 | I18n.locale = :'de-DE' | ||
| 33 | post.subject = 'bar' | ||
| 34 | assert_equal 'bar', post.subject | ||
| 35 | I18n.locale = :'en-US' | ||
| 36 | assert_equal 'foo', post.subject | ||
| 37 | I18n.locale = :'de-DE' | ||
| 38 | post.subject = 'bar' | ||
| 39 | end | ||
| 40 | |||
| 41 | test "has post_translations" do | ||
| 42 | post = Post.create | ||
| 43 | assert_nothing_raised { post.globalize_translations } | ||
| 44 | end | ||
| 45 | |||
| 46 | test "has German post_translations" do | ||
| 47 | I18n.locale = :de | ||
| 48 | post = Post.create :subject => 'foo' | ||
| 49 | assert_equal 1, post.globalize_translations.size | ||
| 50 | I18n.locale = :en | ||
| 51 | assert_equal 1, post.globalize_translations.size | ||
| 52 | end | ||
| 53 | |||
| 54 | test "returns the value passed to :subject" do | ||
| 55 | post = Post.new | ||
| 56 | assert_equal 'foo', (post.subject = 'foo') | ||
| 57 | end | ||
| 58 | |||
| 59 | test "translates subject and content into en-US" do | ||
| 60 | post = Post.create :subject => 'foo', :content => 'bar' | ||
| 61 | assert_equal 'foo', post.subject | ||
| 62 | assert_equal 'bar', post.content | ||
| 63 | assert post.save | ||
| 64 | post.reload | ||
| 65 | assert_equal 'foo', post.subject | ||
| 66 | assert_equal 'bar', post.content | ||
| 67 | end | ||
| 68 | |||
| 69 | test "finds a German post" do | ||
| 70 | post = Post.create :subject => 'foo (en)', :content => 'bar' | ||
| 71 | I18n.locale = 'de-DE' | ||
| 72 | post = Post.first | ||
| 73 | post.subject = 'baz (de)' | ||
| 74 | post.save | ||
| 75 | assert_equal 'baz (de)', Post.first.subject | ||
| 76 | I18n.locale = :'en-US' | ||
| 77 | assert_equal 'foo (en)', Post.first.subject | ||
| 78 | end | ||
| 79 | |||
| 80 | test "saves an English post and loads test correctly" do | ||
| 81 | assert_nil Post.first | ||
| 82 | post = Post.create :subject => 'foo', :content => 'bar' | ||
| 83 | assert post.save | ||
| 84 | post = Post.first | ||
| 85 | assert_equal 'foo', post.subject | ||
| 86 | assert_equal 'bar', post.content | ||
| 87 | end | ||
| 88 | |||
| 89 | test "updates an attribute" do | ||
| 90 | post = Post.create :subject => 'foo', :content => 'bar' | ||
| 91 | post.update_attribute :subject, 'baz' | ||
| 92 | assert_equal 'baz', Post.first.subject | ||
| 93 | end | ||
| 94 | |||
| 95 | test "validates presence of :subject" do | ||
| 96 | post = Post.new | ||
| 97 | assert !post.save | ||
| 98 | |||
| 99 | post = Post.new :subject => 'foo' | ||
| 100 | assert post.save | ||
| 101 | end | ||
| 102 | |||
| 103 | test "returns the value for the correct locale, after locale switching" do | ||
| 104 | post = Post.create :subject => 'foo' | ||
| 105 | I18n.locale = 'de-DE' | ||
| 106 | post.subject = 'bar' | ||
| 107 | post.save | ||
| 108 | I18n.locale = 'en-US' | ||
| 109 | post = Post.first | ||
| 110 | assert_equal 'foo', post.subject | ||
| 111 | I18n.locale = 'de-DE' | ||
| 112 | assert_equal 'bar', post.subject | ||
| 113 | end | ||
| 114 | |||
| 115 | test "keeping one field in new locale when other field is changed" do | ||
| 116 | I18n.fallbacks.map 'de-DE' => [ 'en-US' ] | ||
| 117 | post = Post.create :subject => 'foo' | ||
| 118 | I18n.locale = 'de-DE' | ||
| 119 | post.content = 'bar' | ||
| 120 | assert_equal 'foo', post.subject | ||
| 121 | end | ||
| 122 | |||
| 123 | test "modifying non-required field in a new locale" do | ||
| 124 | I18n.fallbacks.map 'de-DE' => [ 'en-US' ] | ||
| 125 | post = Post.create :subject => 'foo' | ||
| 126 | I18n.locale = 'de-DE' | ||
| 127 | post.content = 'bar' | ||
| 128 | assert post.save | ||
| 129 | end | ||
| 130 | |||
| 131 | test "returns the value for the correct locale, after locale switching, without saving" do | ||
| 132 | post = Post.create :subject => 'foo' | ||
| 133 | I18n.locale = 'de-DE' | ||
| 134 | post.subject = 'bar' | ||
| 135 | I18n.locale = 'en-US' | ||
| 136 | assert_equal 'foo', post.subject | ||
| 137 | I18n.locale = 'de-DE' | ||
| 138 | assert_equal 'bar', post.subject | ||
| 139 | end | ||
| 140 | |||
| 141 | test "saves all locales, even after locale switching" do | ||
| 142 | post = Post.new :subject => 'foo' | ||
| 143 | I18n.locale = 'de-DE' | ||
| 144 | post.subject = 'bar' | ||
| 145 | I18n.locale = 'he-IL' | ||
| 146 | post.subject = 'baz' | ||
| 147 | post.save | ||
| 148 | I18n.locale = 'en-US' | ||
| 149 | post = Post.first | ||
| 150 | assert_equal 'foo', post.subject | ||
| 151 | I18n.locale = 'de-DE' | ||
| 152 | assert_equal 'bar', post.subject | ||
| 153 | I18n.locale = 'he-IL' | ||
| 154 | assert_equal 'baz', post.subject | ||
| 155 | end | ||
| 156 | |||
| 157 | test "resolves a simple fallback" do | ||
| 158 | I18n.locale = 'de-DE' | ||
| 159 | post = Post.create :subject => 'foo' | ||
| 160 | I18n.locale = 'de' | ||
| 161 | post.subject = 'baz' | ||
| 162 | post.content = 'bar' | ||
| 163 | post.save | ||
| 164 | I18n.locale = 'de-DE' | ||
| 165 | assert_equal 'foo', post.subject | ||
| 166 | assert_equal 'bar', post.content | ||
| 167 | end | ||
| 168 | |||
| 169 | test "resolves a simple fallback without reloading" do | ||
| 170 | I18n.locale = 'de-DE' | ||
| 171 | post = Post.new :subject => 'foo' | ||
| 172 | I18n.locale = 'de' | ||
| 173 | post.subject = 'baz' | ||
| 174 | post.content = 'bar' | ||
| 175 | I18n.locale = 'de-DE' | ||
| 176 | assert_equal 'foo', post.subject | ||
| 177 | assert_equal 'bar', post.content | ||
| 178 | end | ||
| 179 | |||
| 180 | test "resolves a complex fallback without reloading" do | ||
| 181 | I18n.fallbacks.map 'de' => %w(en he) | ||
| 182 | I18n.locale = 'de' | ||
| 183 | post = Post.new | ||
| 184 | I18n.locale = 'en' | ||
| 185 | post.subject = 'foo' | ||
| 186 | I18n.locale = 'he' | ||
| 187 | post.subject = 'baz' | ||
| 188 | post.content = 'bar' | ||
| 189 | I18n.locale = 'de' | ||
| 190 | assert_equal 'foo', post.subject | ||
| 191 | assert_equal 'bar', post.content | ||
| 192 | end | ||
| 193 | |||
| 194 | test "returns nil if no translations are found" do | ||
| 195 | post = Post.new :subject => 'foo' | ||
| 196 | assert_equal 'foo', post.subject | ||
| 197 | assert_nil post.content | ||
| 198 | end | ||
| 199 | |||
| 200 | test "returns nil if no translations are found; reloaded" do | ||
| 201 | post = Post.create :subject => 'foo' | ||
| 202 | post = Post.first | ||
| 203 | assert_equal 'foo', post.subject | ||
| 204 | assert_nil post.content | ||
| 205 | end | ||
| 206 | |||
| 207 | test "works with associations" do | ||
| 208 | blog = Blog.create | ||
| 209 | post1 = blog.posts.create :subject => 'foo' | ||
| 210 | I18n.locale = 'de-DE' | ||
| 211 | post2 = blog.posts.create :subject => 'bar' | ||
| 212 | assert_equal 2, blog.posts.size | ||
| 213 | I18n.locale = 'en-US' | ||
| 214 | assert_equal 'foo', blog.posts.first.subject | ||
| 215 | assert_nil blog.posts.last.subject | ||
| 216 | I18n.locale = 'de-DE' | ||
| 217 | assert_equal 'bar', blog.posts.last.subject | ||
| 218 | end | ||
| 219 | |||
| 220 | test "works with simple dynamic finders" do | ||
| 221 | foo = Post.create :subject => 'foo' | ||
| 222 | Post.create :subject => 'bar' | ||
| 223 | post = Post.find_by_subject('foo') | ||
| 224 | assert_equal foo, post | ||
| 225 | end | ||
| 226 | |||
| 227 | test 'change attribute on globalized model' do | ||
| 228 | post = Post.create :subject => 'foo', :content => 'bar' | ||
| 229 | assert_equal [], post.changed | ||
| 230 | post.subject = 'baz' | ||
| 231 | assert_equal [ 'subject' ], post.changed | ||
| 232 | post.content = 'quux' | ||
| 233 | assert_member 'subject', post.changed | ||
| 234 | assert_member 'content', post.changed | ||
| 235 | end | ||
| 236 | |||
| 237 | test 'change attribute on globalized model after locale switching' do | ||
| 238 | post = Post.create :subject => 'foo', :content => 'bar' | ||
| 239 | assert_equal [], post.changed | ||
| 240 | post.subject = 'baz' | ||
| 241 | I18n.locale = :de | ||
| 242 | assert_equal [ 'subject' ], post.changed | ||
| 243 | end | ||
| 244 | |||
| 245 | test 'fallbacks with lots of locale switching' do | ||
| 246 | I18n.fallbacks.map :'de-DE' => [ :'en-US' ] | ||
| 247 | post = Post.create :subject => 'foo' | ||
| 248 | |||
| 249 | I18n.locale = :'de-DE' | ||
| 250 | assert_equal 'foo', post.subject | ||
| 251 | |||
| 252 | I18n.locale = :'en-US' | ||
| 253 | post.update_attribute :subject, 'bar' | ||
| 254 | |||
| 255 | I18n.locale = :'de-DE' | ||
| 256 | assert_equal 'bar', post.subject | ||
| 257 | end | ||
| 258 | end | ||
| 259 | |||
| 260 | # TODO should validate_presence_of take fallbacks into account? maybe we need | ||
| 261 | # an extra validation call, or more options for validate_presence_of. | ||
| 262 | # TODO error checking for fields that exist in main table, don't exist in | ||
| 263 | # proxy table, aren't strings or text | ||
| 264 | # | ||
| 265 | # TODO allow finding by translated attributes in conditions? | ||
| 266 | # TODO generate advanced dynamic finders? | ||
diff --git a/vendor/plugins/globalize2/test/test_helper.rb b/vendor/plugins/globalize2/test/test_helper.rb new file mode 100644 index 0000000..58b047d --- /dev/null +++ b/vendor/plugins/globalize2/test/test_helper.rb | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | require 'rubygems' | ||
| 2 | require 'test/unit' | ||
| 3 | require 'active_support' | ||
| 4 | require 'active_support/test_case' | ||
| 5 | require 'mocha' | ||
| 6 | |||
| 7 | $LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib' ) | ||
| 8 | |||
| 9 | class ActiveSupport::TestCase | ||
| 10 | def reset_db!( schema = 'schema' ) | ||
| 11 | ::ActiveRecord::Migration.verbose = false # Quiet down the migration engine | ||
| 12 | ::ActiveRecord::Base.establish_connection({ | ||
| 13 | :adapter => 'sqlite3', | ||
| 14 | :dbfile => ':memory:' | ||
| 15 | }) | ||
| 16 | ::ActiveRecord::Base.silence do | ||
| 17 | load File.expand_path(File.join(File.dirname(__FILE__), 'data', schema + '.rb')) | ||
| 18 | end | ||
| 19 | end | ||
| 20 | |||
| 21 | def assert_member(item, arr) | ||
| 22 | assert_block "Item #{item} is not in array #{arr}" do | ||
| 23 | arr.member? item | ||
| 24 | end | ||
| 25 | end | ||
| 26 | end \ No newline at end of file | ||
diff --git a/vendor/plugins/globalize2/test/translation_test.rb b/vendor/plugins/globalize2/test/translation_test.rb new file mode 100644 index 0000000..4b52bb1 --- /dev/null +++ b/vendor/plugins/globalize2/test/translation_test.rb | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | require File.join( File.dirname(__FILE__), 'test_helper' ) | ||
| 2 | require 'globalize/translation' | ||
| 3 | |||
| 4 | class TranslationTest < ActiveSupport::TestCase | ||
| 5 | include Globalize | ||
| 6 | |||
| 7 | def setup | ||
| 8 | @translation = Translation::Static.new 'foo', :locale => :'en-US' | ||
| 9 | end | ||
| 10 | |||
| 11 | test "responds to fallback?" do | ||
| 12 | assert @translation.respond_to?( :fallback? ) | ||
| 13 | end | ||
| 14 | |||
| 15 | test "returns true when :locale and :requested_locale are not equal" do | ||
| 16 | @translation.requested_locale = :'de-DE' | ||
| 17 | assert @translation.fallback? | ||
| 18 | end | ||
| 19 | |||
| 20 | test "returns false when :locale and :requested_locale are equal" do | ||
| 21 | @translation.requested_locale = :'en-US' | ||
| 22 | assert !@translation.fallback? | ||
| 23 | end | ||
| 24 | |||
| 25 | test "has the attribute :locale" do | ||
| 26 | assert @translation.respond_to?( :locale ) | ||
| 27 | end | ||
| 28 | |||
| 29 | test "has the attribute :requested_locale" do | ||
| 30 | assert @translation.respond_to?( :requested_locale ) | ||
| 31 | end | ||
| 32 | |||
| 33 | test "has the attribute :options" do | ||
| 34 | assert @translation.respond_to?( :options ) | ||
| 35 | end | ||
| 36 | |||
| 37 | test "has the attribute :plural_key" do | ||
| 38 | assert @translation.respond_to?( :plural_key ) | ||
| 39 | end | ||
| 40 | |||
| 41 | test "has the attribute :original" do | ||
| 42 | assert @translation.respond_to?( :original ) | ||
| 43 | end | ||
| 44 | |||
| 45 | test "Translation::Attribute has the attribute :locale" do | ||
| 46 | translation = Translation::Attribute.new 'foo' | ||
| 47 | assert translation.respond_to?( :locale ) | ||
| 48 | end | ||
| 49 | |||
| 50 | test "Translation::Attribute has the attribute :requested_locale" do | ||
| 51 | translation = Translation::Attribute.new 'foo' | ||
| 52 | assert translation.respond_to?( :requested_locale ) | ||
| 53 | end | ||
| 54 | end | ||
