1 require File.join( File.dirname(__FILE__), '..', 'test_helper' )
 
   2 require 'globalize/backend/pluralizing'
 
   4 class PluralizingTest < ActiveSupport::TestCase
 
   6     @backend = Globalize::Backend::Pluralizing.new
 
   7     @cz_pluralizer = lambda{|c| c == 1 ? :one : (2..4).include?(c) ? :few : :other }
 
  10   test "#pluralizer returns the pluralizer for a given locale if defined" do
 
  11     assert_instance_of Proc, @backend.pluralizer(:en)
 
  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) 
 
  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) 
 
  25 class PluralizePluralizingTest < ActiveSupport::TestCase
 
  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'}
 
  33   test "looks up the :one translation when count is 1" do
 
  34     assert_equal 'one en foo', @backend.translate(:en, :foo, :count => 1) 
 
  37   test "looks up the :other translation when count is 2" do
 
  38     assert_equal 'many en foos', @backend.translate(:en, :foo, :count => 2) 
 
  42 class CzPluralizingTest < ActiveSupport::TestCase
 
  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)
 
  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) 
 
  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)
 
  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)