summaryrefslogtreecommitdiff
path: root/vendor/plugins/globalize2/test/backends/pluralizing_test.rb
diff options
context:
space:
mode:
authorhukl <hukl@eight.local>2009-02-07 15:50:40 +0100
committerhukl <hukl@eight.local>2009-02-07 15:50:40 +0100
commit36a2f1f3c085dd81171cf7d8220770d4ff921ab3 (patch)
tree5ded15331b192bf428af4c94d46d1abb28ef0690 /vendor/plugins/globalize2/test/backends/pluralizing_test.rb
parentce9645d0092d42c7bf8781378181ffbd4ff3d088 (diff)
added globalize2 plugin as well as some modifications
which use the new translation facilities. backend mostly.
Diffstat (limited to 'vendor/plugins/globalize2/test/backends/pluralizing_test.rb')
-rw-r--r--vendor/plugins/globalize2/test/backends/pluralizing_test.rb63
1 files changed, 63 insertions, 0 deletions
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 00000000..7445e3ff
--- /dev/null
+++ b/vendor/plugins/globalize2/test/backends/pluralizing_test.rb
@@ -0,0 +1,63 @@
1require File.join( File.dirname(__FILE__), '..', 'test_helper' )
2require 'globalize/backend/pluralizing'
3
4class 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
23end
24
25class 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
40end
41
42class 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
63end