aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-01-23 05:32:08 +0000
committerRick Olson <technoweenie@gmail.com>2007-01-23 05:32:08 +0000
commitbe7f86e37ac21585ad2621e2e0938c68a7a71360 (patch)
treeac346d834b760ec7a551397a133113a7801cb9cf
parenta44cee2549e04e6e586f0f9432d98bb2dd4e3625 (diff)
downloadrails-be7f86e37ac21585ad2621e2e0938c68a7a71360.tar.gz
rails-be7f86e37ac21585ad2621e2e0938c68a7a71360.tar.bz2
rails-be7f86e37ac21585ad2621e2e0938c68a7a71360.zip
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
-rw-r--r--activesupport/CHANGELOG6
-rw-r--r--activesupport/lib/active_support/duration.rb2
-rw-r--r--activesupport/test/inflector_test.rb33
3 files changed, 40 insertions, 1 deletions
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