activesupport 2.3.5 → 2.3.6.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (121) hide show
  1. data/CHANGELOG +23 -0
  2. data/lib/active_support.rb +1 -0
  3. data/lib/active_support/core_ext/date_time/conversions.rb +14 -3
  4. data/lib/active_support/core_ext/enumerable.rb +6 -0
  5. data/lib/active_support/core_ext/file/atomic.rb +2 -1
  6. data/lib/active_support/core_ext/numeric/conversions.rb +2 -2
  7. data/lib/active_support/core_ext/object.rb +1 -0
  8. data/lib/active_support/core_ext/object/metaclass.rb +6 -5
  9. data/lib/active_support/core_ext/object/singleton_class.rb +13 -0
  10. data/lib/active_support/core_ext/string.rb +0 -1
  11. data/lib/active_support/core_ext/string/output_safety.rb +148 -44
  12. data/lib/active_support/core_ext/time/calculations.rb +1 -1
  13. data/lib/active_support/inflector.rb +1 -1
  14. data/lib/active_support/json/backends/yajl.rb +40 -0
  15. data/lib/active_support/json/decoding.rb +16 -1
  16. data/lib/active_support/json/encoding.rb +11 -2
  17. data/lib/active_support/ordered_hash.rb +24 -1
  18. data/lib/active_support/vendor.rb +10 -2
  19. data/lib/active_support/vendor/i18n-0.3.3/CHANGELOG.textile +76 -0
  20. data/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/MIT-LICENSE +0 -0
  21. data/lib/active_support/vendor/i18n-0.3.3/README.textile +81 -0
  22. data/lib/active_support/vendor/i18n-0.3.3/Rakefile +24 -0
  23. data/lib/active_support/vendor/i18n-0.3.3/benchmark/example.yml +144 -0
  24. data/lib/active_support/vendor/i18n-0.3.3/benchmark/run.rb +71 -0
  25. data/lib/active_support/vendor/i18n-0.3.3/contributors.txt +17 -0
  26. data/lib/active_support/vendor/i18n-0.3.3/i18n.gemspec +165 -0
  27. data/lib/active_support/vendor/i18n-0.3.3/init.rb +1 -0
  28. data/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/lib/i18n.rb +99 -21
  29. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend.rb +17 -0
  30. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record.rb +70 -0
  31. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/missing.rb +67 -0
  32. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/store_procs.rb +38 -0
  33. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/translation.rb +83 -0
  34. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/base.rb +259 -0
  35. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/cache.rb +75 -0
  36. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/cascade.rb +44 -0
  37. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/chain.rb +74 -0
  38. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/fallbacks.rb +52 -0
  39. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/fast.rb +68 -0
  40. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/gettext.rb +75 -0
  41. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/helpers.rb +80 -0
  42. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/interpolation_compiler.rb +119 -0
  43. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/metadata.rb +73 -0
  44. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/pluralization.rb +57 -0
  45. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/simple.rb +22 -0
  46. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/core_ext/object/meta_class.rb +5 -0
  47. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/core_ext/string/interpolate.rb +99 -0
  48. data/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/lib/i18n/exceptions.rb +14 -6
  49. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/gettext.rb +25 -0
  50. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/helpers.rb +5 -0
  51. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/helpers/gettext.rb +64 -0
  52. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale.rb +6 -0
  53. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/fallbacks.rb +98 -0
  54. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag.rb +28 -0
  55. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/parents.rb +24 -0
  56. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/rfc4646.rb +76 -0
  57. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/simple.rb +41 -0
  58. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/version.rb +3 -0
  59. data/lib/active_support/vendor/i18n-0.3.3/test/all.rb +8 -0
  60. data/lib/active_support/vendor/i18n-0.3.3/test/api/basics.rb +15 -0
  61. data/lib/active_support/vendor/i18n-0.3.3/test/api/defaults.rb +40 -0
  62. data/lib/active_support/vendor/i18n-0.3.3/test/api/interpolation.rb +92 -0
  63. data/lib/active_support/vendor/i18n-0.3.3/test/api/link.rb +55 -0
  64. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date.rb +91 -0
  65. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date_time.rb +90 -0
  66. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/procs.rb +54 -0
  67. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/time.rb +84 -0
  68. data/lib/active_support/vendor/i18n-0.3.3/test/api/lookup.rb +45 -0
  69. data/lib/active_support/vendor/i18n-0.3.3/test/api/pluralization.rb +35 -0
  70. data/lib/active_support/vendor/i18n-0.3.3/test/api/procs.rb +40 -0
  71. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/active_record_test.rb +29 -0
  72. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/all_features_test.rb +40 -0
  73. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/cascade_test.rb +31 -0
  74. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/chain_test.rb +26 -0
  75. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fallbacks_test.rb +33 -0
  76. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fast_test.rb +31 -0
  77. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/pluralization_test.rb +33 -0
  78. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/simple_test.rb +21 -0
  79. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record/missing_test.rb +60 -0
  80. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record_test.rb +52 -0
  81. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cache_test.rb +72 -0
  82. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cascade_test.rb +66 -0
  83. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/chain_test.rb +64 -0
  84. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fallbacks_test.rb +57 -0
  85. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fast_test.rb +50 -0
  86. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/helpers_test.rb +26 -0
  87. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/interpolation_compiler_test.rb +107 -0
  88. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/metadata_test.rb +67 -0
  89. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/pluralization_test.rb +43 -0
  90. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/simple_test.rb +77 -0
  91. data/lib/active_support/vendor/i18n-0.3.3/test/cases/core_ext/string/interpolate_test.rb +94 -0
  92. data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/api_test.rb +201 -0
  93. data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/backend_test.rb +91 -0
  94. data/lib/active_support/vendor/{i18n-0.1.3/test → i18n-0.3.3/test/cases}/i18n_exceptions_test.rb +8 -10
  95. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_load_path_test.rb +23 -0
  96. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_test.rb +172 -0
  97. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/fallbacks_test.rb +126 -0
  98. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/rfc4646_test.rb +143 -0
  99. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/simple_test.rb +33 -0
  100. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/de.po +72 -0
  101. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.rb +3 -0
  102. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.yml +3 -0
  103. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/plurals.rb +113 -0
  104. data/lib/active_support/vendor/i18n-0.3.3/test/test_helper.rb +100 -0
  105. data/lib/active_support/vendor/i18n-0.3.3/vendor/po_parser.rb +329 -0
  106. data/lib/active_support/version.rb +1 -1
  107. data/lib/active_support/whiny_nil.rb +1 -1
  108. data/lib/active_support/xml_mini/libxml.rb +23 -83
  109. data/lib/active_support/xml_mini/libxmlsax.rb +74 -0
  110. data/lib/active_support/xml_mini/nokogiri.rb +25 -22
  111. data/lib/active_support/xml_mini/nokogirisax.rb +73 -0
  112. metadata +108 -20
  113. data/lib/active_support/vendor/i18n-0.1.3/README.textile +0 -20
  114. data/lib/active_support/vendor/i18n-0.1.3/Rakefile +0 -5
  115. data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +0 -27
  116. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +0 -214
  117. data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +0 -5
  118. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -124
  119. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +0 -1
  120. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +0 -3
  121. data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -567
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ module Tests
4
+ module Api
5
+ module Procs
6
+ define_method "test lookup: given a translation is a proc it calls the proc with the key and interpolation values" do
7
+ store_translations(:a_lambda => lambda { |*args| args.inspect })
8
+ assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:a_lambda, :foo => 'foo')
9
+ end
10
+
11
+ define_method "test defaults: given a default is a Proc it calls it with the key and interpolation values" do
12
+ proc = lambda { |*args| args.inspect }
13
+ assert_equal '[nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo')
14
+ end
15
+
16
+ define_method "test defaults: given a default is a key that resolves to a Proc it calls it with the key and interpolation values" do
17
+ store_translations(:a_lambda => lambda { |*args| args.inspect })
18
+ assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => :a_lambda, :foo => 'foo')
19
+ assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => [nil, :a_lambda], :foo => 'foo')
20
+ end
21
+
22
+ define_method "test interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do
23
+ proc = lambda { |*args| args.inspect }
24
+ assert_match %r(\[\{:foo=>#<Proc.*>\}\]), I18n.t(nil, :default => '{{foo}}', :foo => proc)
25
+ end
26
+
27
+ define_method "test interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do
28
+ proc = lambda { |*args| "{{foo}}: " + args.inspect }
29
+ assert_equal 'foo: [nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo')
30
+ end
31
+
32
+ define_method "test pluralization: given a key resolves to a Proc that returns valid data then pluralization still works" do
33
+ proc = lambda { |*args| { :zero => 'zero', :one => 'one', :other => 'other' } }
34
+ assert_equal 'zero', I18n.t(:default => proc, :count => 0)
35
+ assert_equal 'one', I18n.t(:default => proc, :count => 1)
36
+ assert_equal 'other', I18n.t(:default => proc, :count => 2)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
3
+
4
+ setup_active_record
5
+
6
+
7
+ class I18nActiveRecordApiTest < Test::Unit::TestCase
8
+ def setup
9
+ I18n.backend = I18n::Backend::ActiveRecord.new
10
+ super
11
+ end
12
+
13
+ include Tests::Api::Basics
14
+ include Tests::Api::Defaults
15
+ include Tests::Api::Interpolation
16
+ include Tests::Api::Link
17
+ include Tests::Api::Lookup
18
+ include Tests::Api::Pluralization
19
+ include Tests::Api::Procs unless RUBY_VERSION >= '1.9.1'
20
+
21
+ include Tests::Api::Localization::Date
22
+ include Tests::Api::Localization::DateTime
23
+ include Tests::Api::Localization::Time
24
+ include Tests::Api::Localization::Procs unless RUBY_VERSION >= '1.9.1'
25
+
26
+ define_method "test: make sure we use an ActiveRecord backend" do
27
+ assert_equal I18n::Backend::ActiveRecord, I18n.backend.class
28
+ end
29
+ end if defined?(ActiveRecord)
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nAllFeaturesApiTest < Test::Unit::TestCase
6
+ class Backend
7
+ include I18n::Backend::Base
8
+ include I18n::Backend::Cache
9
+ include I18n::Backend::Metadata
10
+ include I18n::Backend::Cascade
11
+ include I18n::Backend::Fallbacks
12
+ include I18n::Backend::Pluralization
13
+ include I18n::Backend::Fast
14
+ include I18n::Backend::InterpolationCompiler
15
+ end
16
+
17
+ def setup
18
+ I18n.backend = I18n::Backend::Chain.new(Backend.new, I18n::Backend::Simple.new)
19
+ super
20
+ end
21
+
22
+ include Tests::Api::Basics
23
+ include Tests::Api::Defaults
24
+ include Tests::Api::Interpolation
25
+ include Tests::Api::Link
26
+ include Tests::Api::Lookup
27
+ include Tests::Api::Pluralization
28
+ include Tests::Api::Procs
29
+ include Tests::Api::Localization::Date
30
+ include Tests::Api::Localization::DateTime
31
+ include Tests::Api::Localization::Time
32
+ include Tests::Api::Localization::Procs
33
+
34
+ define_method "test: make sure we use a Chain backend with an all features backend" do
35
+ assert_equal I18n::Backend::Chain, I18n.backend.class
36
+ assert_equal Backend, I18n.backend.backends.first.class
37
+ end
38
+
39
+ # links: test that keys stored on one backend can link to keys stored on another backend
40
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nCascadeApiTest < Test::Unit::TestCase
6
+ class Backend
7
+ include I18n::Backend::Base
8
+ include I18n::Backend::Cascade
9
+ end
10
+
11
+ def setup
12
+ I18n.backend = Backend.new
13
+ super
14
+ end
15
+
16
+ include Tests::Api::Basics
17
+ include Tests::Api::Defaults
18
+ include Tests::Api::Interpolation
19
+ include Tests::Api::Link
20
+ include Tests::Api::Lookup
21
+ include Tests::Api::Pluralization
22
+ include Tests::Api::Procs
23
+ include Tests::Api::Localization::Date
24
+ include Tests::Api::Localization::DateTime
25
+ include Tests::Api::Localization::Time
26
+ include Tests::Api::Localization::Procs
27
+
28
+ define_method "test: make sure we use a backend with Cascade included" do
29
+ assert_equal Backend, I18n.backend.class
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nApiChainTest < Test::Unit::TestCase
6
+ def setup
7
+ super
8
+ I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
9
+ end
10
+
11
+ include Tests::Api::Basics
12
+ include Tests::Api::Defaults
13
+ include Tests::Api::Interpolation
14
+ include Tests::Api::Link
15
+ include Tests::Api::Lookup
16
+ include Tests::Api::Pluralization
17
+ include Tests::Api::Procs
18
+ include Tests::Api::Localization::Date
19
+ include Tests::Api::Localization::DateTime
20
+ include Tests::Api::Localization::Time
21
+ include Tests::Api::Localization::Procs
22
+
23
+ define_method "test: make sure we use the Chain backend" do
24
+ assert_equal I18n::Backend::Chain, I18n.backend.class
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nFallbacksApiTest < Test::Unit::TestCase
6
+ class Backend
7
+ include I18n::Backend::Base
8
+ include I18n::Backend::Fallbacks
9
+ end
10
+
11
+ def setup
12
+ I18n.backend = Backend.new
13
+ super
14
+ end
15
+
16
+ include Tests::Api::Basics
17
+ include Tests::Api::Defaults
18
+ include Tests::Api::Interpolation
19
+ include Tests::Api::Link
20
+ include Tests::Api::Lookup
21
+ include Tests::Api::Pluralization
22
+ include Tests::Api::Procs
23
+ include Tests::Api::Localization::Date
24
+ include Tests::Api::Localization::DateTime
25
+ include Tests::Api::Localization::Time
26
+ include Tests::Api::Localization::Procs
27
+
28
+ define_method "test: make sure we use a backend with Fallbacks included" do
29
+ assert_equal Backend, I18n.backend.class
30
+ end
31
+
32
+ # links: test that keys stored on one backend can link to keys stored on another backend
33
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nFastBackendApiTest < Test::Unit::TestCase
6
+ include Tests::Api::Basics
7
+ include Tests::Api::Defaults
8
+ include Tests::Api::Interpolation
9
+ include Tests::Api::Link
10
+ include Tests::Api::Lookup
11
+ include Tests::Api::Pluralization
12
+ include Tests::Api::Procs
13
+ include Tests::Api::Localization::Date
14
+ include Tests::Api::Localization::DateTime
15
+ include Tests::Api::Localization::Time
16
+ include Tests::Api::Localization::Procs
17
+
18
+ class FastBackend
19
+ include I18n::Backend::Base
20
+ include I18n::Backend::Fast
21
+ end
22
+
23
+ def setup
24
+ I18n.backend = FastBackend.new
25
+ super
26
+ end
27
+
28
+ define_method "test: make sure we use the FastBackend backend" do
29
+ assert_equal FastBackend, I18n.backend.class
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nPluralizationApiTest < Test::Unit::TestCase
6
+ class Backend
7
+ include I18n::Backend::Base
8
+ include I18n::Backend::Pluralization
9
+ end
10
+
11
+ def setup
12
+ I18n.backend = Backend.new
13
+ super
14
+ end
15
+
16
+ include Tests::Api::Basics
17
+ include Tests::Api::Defaults
18
+ include Tests::Api::Interpolation
19
+ include Tests::Api::Link
20
+ include Tests::Api::Lookup
21
+ include Tests::Api::Pluralization
22
+ include Tests::Api::Procs
23
+ include Tests::Api::Localization::Date
24
+ include Tests::Api::Localization::DateTime
25
+ include Tests::Api::Localization::Time
26
+ include Tests::Api::Localization::Procs
27
+
28
+ define_method "test: make sure we use a backend with Pluralization included" do
29
+ assert_equal Backend, I18n.backend.class
30
+ end
31
+
32
+ # links: test that keys stored on one backend can link to keys stored on another backend
33
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nSimpleBackendApiTest < Test::Unit::TestCase
6
+ include Tests::Api::Basics
7
+ include Tests::Api::Defaults
8
+ include Tests::Api::Interpolation
9
+ include Tests::Api::Link
10
+ include Tests::Api::Lookup
11
+ include Tests::Api::Pluralization
12
+ include Tests::Api::Procs
13
+ include Tests::Api::Localization::Date
14
+ include Tests::Api::Localization::DateTime
15
+ include Tests::Api::Localization::Time
16
+ include Tests::Api::Localization::Procs
17
+
18
+ define_method "test: make sure we use the Simple backend" do
19
+ assert_equal I18n::Backend::Simple, I18n.backend.class
20
+ end
21
+ end
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
3
+
4
+ setup_active_record
5
+
6
+ class I18nActiveRecordMissingTest < Test::Unit::TestCase
7
+ def setup
8
+ store_translations(:en, :i18n => { :plural => { :keys => [:zero, :one, :other] } })
9
+
10
+ I18n.backend = I18n::Backend::Chain.new(I18n.backend)
11
+ I18n.backend.meta_class.send(:include, I18n::Backend::ActiveRecord::Missing)
12
+
13
+ I18n::Backend::ActiveRecord::Translation.delete_all
14
+ end
15
+
16
+ def test_can_persist_interpolations
17
+ translation = I18n::Backend::ActiveRecord::Translation.new \
18
+ :key => 'foo',
19
+ :value => 'bar',
20
+ :locale => :en
21
+
22
+ translation.interpolations = %w{ count name }
23
+ translation.save
24
+
25
+ assert translation.valid?
26
+ end
27
+
28
+ def test_lookup_persists_key
29
+ I18n.t('foo.bar.baz')
30
+
31
+ assert_equal 1, I18n::Backend::ActiveRecord::Translation.count
32
+ end
33
+
34
+ def test_lookup_does_not_persist_key_twice
35
+ 2.times { I18n.t('foo.bar.baz') }
36
+
37
+ assert_equal 1, I18n::Backend::ActiveRecord::Translation.count
38
+ end
39
+
40
+ def test_persists_interpolation_keys_when_looked_up_directly
41
+ I18n.t('foo.bar.baz', :cow => "lucy" ) # creates stub translation.
42
+
43
+ translation_stub = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo.bar.baz').first
44
+ assert translation_stub.interpolates?(:cow)
45
+ end
46
+
47
+ def test_creates_one_stub_per_pluralization
48
+ I18n.t('foo', :count => 999)
49
+
50
+ translations = I18n::Backend::ActiveRecord::Translation.locale(:en).find_all_by_key %w{ foo.zero foo.one foo.other }
51
+ assert_equal 3, translations.length
52
+ end
53
+
54
+ def test_creates_no_stub_for_base_key_in_pluralization
55
+ I18n.t('foo', :count => 999)
56
+
57
+ translations = I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key %w{ foo.zero foo.one foo.other }
58
+ assert !I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key("foo")
59
+ end
60
+ end if defined?(ActiveRecord)
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
3
+
4
+ setup_active_record
5
+
6
+
7
+ class I18nBackendActiveRecordTest < Test::Unit::TestCase
8
+ def setup
9
+ I18n.backend = I18n::Backend::ActiveRecord.new
10
+ store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' })
11
+ end
12
+
13
+ def teardown
14
+ I18n::Backend::ActiveRecord::Translation.destroy_all
15
+ super
16
+ end
17
+
18
+ def test_store_translations_does_not_allow_ambigous_keys_1
19
+ I18n::Backend::ActiveRecord::Translation.delete_all
20
+ I18n.backend.store_translations(:en, :foo => 'foo')
21
+ I18n.backend.store_translations(:en, :foo => { :bar => 'bar' })
22
+ I18n.backend.store_translations(:en, :foo => { :baz => 'baz' })
23
+
24
+ translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo', '.').all
25
+ assert_equal %w(bar baz), translations.map(&:value)
26
+
27
+ assert_equal({ :bar => 'bar', :baz => 'baz' }, I18n.t(:foo))
28
+ end
29
+
30
+ def test_store_translations_does_not_allow_ambigous_keys_2
31
+ I18n::Backend::ActiveRecord::Translation.delete_all
32
+ I18n.backend.store_translations(:en, :foo => { :bar => 'bar' })
33
+ I18n.backend.store_translations(:en, :foo => { :baz => 'baz' })
34
+ I18n.backend.store_translations(:en, :foo => 'foo')
35
+
36
+ translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo', '.').all
37
+ assert_equal %w(foo), translations.map(&:value)
38
+
39
+ assert_equal 'foo', I18n.t(:foo)
40
+ end
41
+
42
+ with_mocha do
43
+ def test_missing_translations_table_does_not_cause_available_locales_to_error
44
+ I18n::Backend::ActiveRecord::Translation.expects(:available_locales).raises(::ActiveRecord::StatementInvalid)
45
+ assert_equal [], I18n.backend.available_locales
46
+ end
47
+ end
48
+
49
+ def test_expand_keys
50
+ assert_equal %w(foo foo.bar foo.bar.baz), I18n.backend.send(:expand_keys, :'foo.bar.baz')
51
+ end
52
+ end if defined?(ActiveRecord)
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+ require 'i18n/backend/cache'
5
+
6
+ begin
7
+ require 'active_support'
8
+ rescue LoadError
9
+ $stderr.puts "Skipping cache tests using ActiveSupport"
10
+ else
11
+
12
+ class I18nBackendCacheTest < Test::Unit::TestCase
13
+ class Backend
14
+ include I18n::Backend::Base
15
+ include I18n::Backend::Cache
16
+ end
17
+
18
+ def setup
19
+ I18n.backend = Backend.new
20
+ super
21
+ I18n.cache_store = ActiveSupport::Cache.lookup_store(:memory_store)
22
+ end
23
+
24
+ def teardown
25
+ I18n.cache_store = nil
26
+ end
27
+
28
+ def test_uses_cache
29
+ assert I18n.cache_store.is_a?(ActiveSupport::Cache::MemoryStore)
30
+ end
31
+
32
+ with_mocha do
33
+ define_method "test translate hits the backend and caches the response" do
34
+ I18n.backend.expects(:lookup).returns('Foo')
35
+ assert_equal 'Foo', I18n.t(:foo)
36
+
37
+ I18n.backend.expects(:lookup).never
38
+ assert_equal 'Foo', I18n.t(:foo)
39
+
40
+ I18n.backend.expects(:lookup).returns('Bar')
41
+ assert_equal 'Bar', I18n.t(:bar)
42
+ end
43
+
44
+ define_method "test still raises MissingTranslationData but also caches it" do
45
+ I18n.backend.expects(:lookup).returns(nil)
46
+ assert_raises(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
47
+
48
+ I18n.backend.expects(:lookup).never
49
+ assert_raises(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
50
+ end
51
+ end
52
+
53
+ define_method "test uses 'i18n' as a cache key namespace by default" do
54
+ assert_equal 0, I18n.backend.send(:cache_key, :foo).index('i18n')
55
+ end
56
+
57
+ define_method "test adds a custom cache key namespace" do
58
+ with_cache_namespace('bar') do
59
+ assert_equal 0, I18n.backend.send(:cache_key, :foo).index('i18n-bar')
60
+ end
61
+ end
62
+
63
+ protected
64
+
65
+ def with_cache_namespace(namespace)
66
+ I18n.cache_namespace = namespace
67
+ yield
68
+ I18n.cache_namespace = nil
69
+ end
70
+ end
71
+
72
+ end # AS cache check