提交 be7f86e3 编写于 作者: R Rick Olson

Added test coverage for Inflector.inflections.clear. Closes #7179. [Rich...

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
上级 a44cee25
*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]
......
......@@ -55,7 +55,7 @@ def ago(time = ::Time.now)
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
......
......@@ -327,4 +327,37 @@ def test_underscore_to_lower_camel
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册