From be7f86e37ac21585ad2621e2e0938c68a7a71360 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Tue, 23 Jan 2007 05:32:08 +0000 Subject: Added test coverage for Inflector.inflections.clear. Closes #7179. [Rich Collins]. Remove unused code from Duration#inspect. Closes #7180. [Rich Collins] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6022 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/CHANGELOG | 6 +++++ activesupport/lib/active_support/duration.rb | 2 +- activesupport/test/inflector_test.rb | 33 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index fcb79ca344..2219d1fd7e 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,11 @@ *SVN* +* Remove unused code from Duration#inspect. Closes #7180. [Rich Collins] + +* Added test coverage for Inflector.inflections.clear. Closes #7179. [Rich Collins] + +* ActiveSupport::Multibyte::Handlers::UTF8Handler should raise when a range and an integer are passed in (just like the native implementation). Closes #7176 [Rich Collins] + * A couple extra tests for #classify. Closes #7273. [Josh Susser] * Better docs for Object extensions [zackchandler, Jamis Buck] diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 8e518cb00b..5279c4435a 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -55,7 +55,7 @@ module ActiveSupport def inspect #:nodoc: consolidated = parts.inject(Hash.new(0)) { |h,part| h[part.first] += part.last; h } - [:years, :months, :days, :hours, :minutes, :seconds].map do |length| + [:years, :months, :days, :minutes, :seconds].map do |length| n = consolidated[length] "#{n} #{n == 1 ? length.to_s.singularize : length.to_s}" if n.nonzero? end.compact.to_sentence diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 7dace1a7a9..d068a9892f 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -327,4 +327,37 @@ class InflectorTest < Test::Unit::TestCase assert_equal(lower_camel, Inflector.camelize(underscored, false)) end end + + %w{plurals singulars uncountables}.each do |inflection_type| + class_eval " + def test_clear_#{inflection_type} + cached_values = Inflector.inflections.#{inflection_type} + Inflector.inflections.clear :#{inflection_type} + assert Inflector.inflections.#{inflection_type}.empty?, \"#{inflection_type} inflections should be empty after clear :#{inflection_type}\" + Inflector.inflections.instance_variable_set :@#{inflection_type}, cached_values + end + " + end + + def test_clear_all + cached_values = Inflector.inflections.plurals, Inflector.inflections.singulars, Inflector.inflections.uncountables + Inflector.inflections.clear :all + assert Inflector.inflections.plurals.empty? + assert Inflector.inflections.singulars.empty? + assert Inflector.inflections.uncountables.empty? + Inflector.inflections.instance_variable_set :@plurals, cached_values[0] + Inflector.inflections.instance_variable_set :@singulars, cached_values[1] + Inflector.inflections.instance_variable_set :@uncountables, cached_values[2] + end + + def test_clear_with_default + cached_values = Inflector.inflections.plurals, Inflector.inflections.singulars, Inflector.inflections.uncountables + Inflector.inflections.clear + assert Inflector.inflections.plurals.empty? + assert Inflector.inflections.singulars.empty? + assert Inflector.inflections.uncountables.empty? + Inflector.inflections.instance_variable_set :@plurals, cached_values[0] + Inflector.inflections.instance_variable_set :@singulars, cached_values[1] + Inflector.inflections.instance_variable_set :@uncountables, cached_values[2] + end end -- cgit v1.2.3