Skip to content

Commit

Permalink
Fixed Inflector.underscore for use with acronyms, so HTML becomes htm…
Browse files Browse the repository at this point in the history
…l instead of htm_l #2173 [k@v2studio.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2227 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Sep 13, 2005
1 parent a658359 commit 426fa08
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Fixed Inflector.underscore for use with acronyms, so HTML becomes html instead of htm_l #2173 [k@v2studio.com]

* Fixed dependencies related infinite recursion bug when a controller file does not contain a controller class. Closes #1760. [rcolli2@tampabay.rr.com]

* Fixed inflections for status, quiz, move #2056 [deirdre@deirdre.net]
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/inflector.rb
Expand Up @@ -114,7 +114,7 @@ def camelize(lower_case_and_underscored_word)
end

def underscore(camel_cased_word)
camel_cased_word.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase
camel_cased_word.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase
end

def humanize(lower_case_and_underscored_word)
Expand Down
15 changes: 11 additions & 4 deletions activesupport/test/inflector_test.rb
Expand Up @@ -109,7 +109,14 @@ class InflectorTest < Test::Unit::TestCase
"Product" => "product",
"SpecialGuest" => "special_guest",
"ApplicationController" => "application_controller",
"Area51Controller" => "area51_controller"
"Area51Controller" => "area51_controller",
}

CamelToUnderscoreWithoutReverse = {
"HTMLTidy" => "html_tidy",
"HTMLTidyGenerator" => "html_tidy_generator",
"FreeBSD" => "free_bsd",
"HTML" => "html",
}

CamelWithModuleToUnderscoreWithSlash = {
Expand Down Expand Up @@ -199,9 +206,9 @@ def test_underscore
CamelToUnderscore.each do |camel, underscore|
assert_equal(underscore, Inflector.underscore(camel))
end

assert_equal "html_tidy", Inflector.underscore("HTMLTidy")
assert_equal "html_tidy_generator", Inflector.underscore("HTMLTidyGenerator")
CamelToUnderscoreWithoutReverse.each do |camel, underscore|
assert_equal(underscore, Inflector.underscore(camel))
end
end

def test_camelize_with_module
Expand Down

0 comments on commit 426fa08

Please sign in to comment.