From ba9891f13da80bf5991c50ce53ab9db3fe852600 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Mon, 25 Apr 2011 02:17:22 +0100 Subject: [PATCH] proper reset all inflector scopes --- .../lib/active_support/inflector/inflections.rb | 2 +- activesupport/test/inflector_test.rb | 42 ++++++++++++++------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/activesupport/lib/active_support/inflector/inflections.rb b/activesupport/lib/active_support/inflector/inflections.rb index e136e4c..d5d55b7 100644 --- a/activesupport/lib/active_support/inflector/inflections.rb +++ b/activesupport/lib/active_support/inflector/inflections.rb @@ -96,7 +96,7 @@ module ActiveSupport def clear(scope = :all) case scope when :all - @plurals, @singulars, @uncountables = [], [], [] + @plurals, @singulars, @uncountables, @humans = [], [], [], [] else instance_variable_set "@#{scope}", [] end diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 1670d9e..95f1812 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -255,12 +255,21 @@ class InflectorTest < Test::Unit::TestCase end def test_clear_all - 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? + cached_values = ActiveSupport::Inflector.inflections.plurals.dup, ActiveSupport::Inflector.inflections.singulars.dup, ActiveSupport::Inflector.inflections.uncountables.dup, ActiveSupport::Inflector.inflections.humans.dup + ActiveSupport::Inflector.inflections do |inflect| + # ensure any data is present + inflect.plural(/(quiz)$/i, '\1zes') + inflect.singular(/(database)s$/i, '\1') + inflect.uncountable('series') + inflect.human("col_rpted_bugs", "Reported bugs") + + inflect.clear :all + + assert inflect.plurals.empty? + assert inflect.singulars.empty? + assert inflect.uncountables.empty? + assert inflect.humans.empty? + end 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] @@ -268,12 +277,21 @@ class InflectorTest < Test::Unit::TestCase end def test_clear_with_default - 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? + cached_values = ActiveSupport::Inflector.inflections.plurals.dup, ActiveSupport::Inflector.inflections.singulars.dup, ActiveSupport::Inflector.inflections.uncountables.dup, ActiveSupport::Inflector.inflections.humans.dup + ActiveSupport::Inflector.inflections do |inflect| + # ensure any data is present + inflect.plural(/(quiz)$/i, '\1zes') + inflect.singular(/(database)s$/i, '\1') + inflect.uncountable('series') + inflect.human("col_rpted_bugs", "Reported bugs") + + inflect.clear + + assert inflect.plurals.empty? + assert inflect.singulars.empty? + assert inflect.uncountables.empty? + assert inflect.humans.empty? + end 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] -- 1.7.4.4