aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2012-06-21 02:16:48 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2012-06-21 02:16:48 -0700
commitfe933be5e20363c21c7989172fab5844ea8abd68 (patch)
tree09e66dfcbaa5676f23ac32906b294eac0ba27474
parent26a4e5e60e4875e77a91fee5a9655d54f3635972 (diff)
downloadrails-fe933be5e20363c21c7989172fab5844ea8abd68.tar.gz
rails-fe933be5e20363c21c7989172fab5844ea8abd68.tar.bz2
rails-fe933be5e20363c21c7989172fab5844ea8abd68.zip
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.
-rw-r--r--activesupport/test/inflector_test.rb10
-rw-r--r--activesupport/test/inflector_test_cases.rb2
2 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb
index 91ae6bc189..1f32e4ff92 100644
--- a/activesupport/test/inflector_test.rb
+++ b/activesupport/test/inflector_test.rb
@@ -413,6 +413,16 @@ class InflectorTest < ActiveSupport::TestCase
end
end
+ Irregularities.each do |irregularity|
+ singular, plural = *irregularity
+ ActiveSupport::Inflector.inflections do |inflect|
+ define_method("test_singularize_of_irregularity_#{singular}_should_be_the_same") do
+ inflect.irregular(singular, plural)
+ assert_equal singular, ActiveSupport::Inflector.singularize(singular)
+ end
+ end
+ end
+
[ :all, [] ].each do |scope|
ActiveSupport::Inflector.inflections do |inflect|
define_method("test_clear_inflections_with_#{scope.kind_of?(Array) ? "no_arguments" : scope}") do
diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb
index 9fa1f417e4..ca4efd2e59 100644
--- a/activesupport/test/inflector_test_cases.rb
+++ b/activesupport/test/inflector_test_cases.rb
@@ -308,5 +308,7 @@ module InflectorTestCases
'child' => 'children',
'sex' => 'sexes',
'move' => 'moves',
+ 'cow' => 'kine',
+ 'zombie' => 'zombies',
}
end