Skip to content
This repository
Browse code

Adds missing inflector tests to ensure idempotency

This is a follow up to #4719. It appears that singularize and pluralize
are supposed to be idempotent - i.e. when you call singularize or
pluralize multiple times on the same string, you should get the same
result. (At least for the "officially supported" cases that the stock
inflector is designed to handle.) #4719 added the missing tests for
regular cases, and this commit added the missing tests for the
irregularities.

While I'm at that, I also synced up the irregularity test cases with
the current set of irregularity cases that we ship out-of-the-box.
  • Loading branch information...
commit fe933be5e20363c21c7989172fab5844ea8abd68 1 parent 26a4e5e
Godfrey Chan authored June 21, 2012
10  activesupport/test/inflector_test.rb
@@ -413,6 +413,16 @@ def test_clear_with_default
413 413
     end
414 414
   end
415 415
 
  416
+  Irregularities.each do |irregularity|
  417
+    singular, plural = *irregularity
  418
+    ActiveSupport::Inflector.inflections do |inflect|
  419
+      define_method("test_singularize_of_irregularity_#{singular}_should_be_the_same") do
  420
+        inflect.irregular(singular, plural)
  421
+        assert_equal singular, ActiveSupport::Inflector.singularize(singular)
  422
+      end
  423
+    end
  424
+  end
  425
+
416 426
   [ :all, [] ].each do |scope|
417 427
     ActiveSupport::Inflector.inflections do |inflect|
418 428
       define_method("test_clear_inflections_with_#{scope.kind_of?(Array) ? "no_arguments" : scope}") do
2  activesupport/test/inflector_test_cases.rb
@@ -308,5 +308,7 @@ module InflectorTestCases
308 308
     'child'  => 'children',
309 309
     'sex'    => 'sexes',
310 310
     'move'   => 'moves',
  311
+    'cow'    => 'kine',
  312
+    'zombie' => 'zombies',
311 313
   }
312 314
 end

0 notes on commit fe933be

Please sign in to comment.
Something went wrong with that request. Please try again.