diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-07-02 13:25:17 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-07-02 13:25:36 +0100 |
commit | 4f75840d72b96fff34d65b59480da7d6c7494120 (patch) | |
tree | cd13f9cf0359811c262e47737e704b059312ee05 /activesupport/test | |
parent | 3a95ee73cfbcfeada3b053c5b0fb7b5125ef12c7 (diff) | |
download | rails-4f75840d72b96fff34d65b59480da7d6c7494120.tar.gz rails-4f75840d72b96fff34d65b59480da7d6c7494120.tar.bz2 rails-4f75840d72b96fff34d65b59480da7d6c7494120.zip |
Add Inflection rules for String#humanize. [#535 state:resolved] [dcmanges]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/inflector_test.rb | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 4ce9cbb705..6c0c14e866 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -110,6 +110,23 @@ class InflectorTest < Test::Unit::TestCase end end + def test_humanize_by_rule + ActiveSupport::Inflector.inflections do |inflect| + inflect.human(/_cnt$/i, '\1_count') + inflect.human(/^prefx_/i, '\1') + end + assert_equal("Jargon count", ActiveSupport::Inflector.humanize("jargon_cnt")) + assert_equal("Request", ActiveSupport::Inflector.humanize("prefx_request")) + end + + def test_humanize_by_string + ActiveSupport::Inflector.inflections do |inflect| + inflect.human("col_rpted_bugs", "Reported bugs") + end + assert_equal("Reported bugs", ActiveSupport::Inflector.humanize("col_rpted_bugs")) + assert_equal("Col rpted bugs", ActiveSupport::Inflector.humanize("COL_rpted_bugs")) + end + def test_constantize assert_nothing_raised { assert_equal Ace::Base::Case, ActiveSupport::Inflector.constantize("Ace::Base::Case") } assert_nothing_raised { assert_equal Ace::Base::Case, ActiveSupport::Inflector.constantize("::Ace::Base::Case") } @@ -148,7 +165,7 @@ class InflectorTest < Test::Unit::TestCase end end - %w{plurals singulars uncountables}.each do |inflection_type| + %w{plurals singulars uncountables humans}.each do |inflection_type| class_eval " def test_clear_#{inflection_type} cached_values = ActiveSupport::Inflector.inflections.#{inflection_type} @@ -160,25 +177,29 @@ class InflectorTest < Test::Unit::TestCase end def test_clear_all - cached_values = ActiveSupport::Inflector.inflections.plurals, ActiveSupport::Inflector.inflections.singulars, ActiveSupport::Inflector.inflections.uncountables + cached_values = ActiveSupport::Inflector.inflections.plurals, ActiveSupport::Inflector.inflections.singulars, ActiveSupport::Inflector.inflections.uncountables, ActiveSupport::Inflector.inflections.humans ActiveSupport::Inflector.inflections.clear :all assert ActiveSupport::Inflector.inflections.plurals.empty? assert ActiveSupport::Inflector.inflections.singulars.empty? assert ActiveSupport::Inflector.inflections.uncountables.empty? + assert ActiveSupport::Inflector.inflections.humans.empty? ActiveSupport::Inflector.inflections.instance_variable_set :@plurals, cached_values[0] ActiveSupport::Inflector.inflections.instance_variable_set :@singulars, cached_values[1] ActiveSupport::Inflector.inflections.instance_variable_set :@uncountables, cached_values[2] + ActiveSupport::Inflector.inflections.instance_variable_set :@humans, cached_values[3] end def test_clear_with_default - cached_values = ActiveSupport::Inflector.inflections.plurals, ActiveSupport::Inflector.inflections.singulars, ActiveSupport::Inflector.inflections.uncountables + cached_values = ActiveSupport::Inflector.inflections.plurals, ActiveSupport::Inflector.inflections.singulars, ActiveSupport::Inflector.inflections.uncountables, ActiveSupport::Inflector.inflections.humans ActiveSupport::Inflector.inflections.clear assert ActiveSupport::Inflector.inflections.plurals.empty? assert ActiveSupport::Inflector.inflections.singulars.empty? assert ActiveSupport::Inflector.inflections.uncountables.empty? + assert ActiveSupport::Inflector.inflections.humans.empty? ActiveSupport::Inflector.inflections.instance_variable_set :@plurals, cached_values[0] ActiveSupport::Inflector.inflections.instance_variable_set :@singulars, cached_values[1] ActiveSupport::Inflector.inflections.instance_variable_set :@uncountables, cached_values[2] + ActiveSupport::Inflector.inflections.instance_variable_set :@humans, cached_values[3] end Irregularities.each do |irregularity| @@ -217,7 +238,7 @@ class InflectorTest < Test::Unit::TestCase end end - { :singulars => :singular, :plurals => :plural, :uncountables => :uncountable }.each do |scope, method| + { :singulars => :singular, :plurals => :plural, :uncountables => :uncountable, :humans => :human }.each do |scope, method| ActiveSupport::Inflector.inflections do |inflect| define_method("test_clear_inflections_with_#{scope}") do # save the inflections |