Fix #camelize for terms with both underscore and camelcase #5302

Closed
wants to merge 1 commit into
from
@@ -58,7 +58,7 @@ def camelize(term, uppercase_first_letter = true)
else
string = string.sub(/^(?:#{inflections.acronym_regex}(?=\b|[A-Z_])|\w)/) { $&.downcase }
end
- string.gsub(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{inflections.acronyms[$2] || $2.capitalize}" }.gsub('/', '::')
+ string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{inflections.acronyms[$2] || $2.capitalize}" }.gsub('/', '::')
end
# Makes an underscored, lowercase form from the expression in the string.
@@ -98,6 +98,14 @@ def test_camelize_with_underscores
assert_equal("CamelCase", ActiveSupport::Inflector.camelize('Camel_Case'))
end
+ def test_camelize_with_camelcase
+ assert_equal("CamelCase", ActiveSupport::Inflector.camelize('CamelCase'))
+ end
+
+ def test_camelize_with_mixed
+ assert_equal("CamelCaseMixedWithUnderscore", ActiveSupport::Inflector.camelize('_CamelCase_mixedWith_Underscore'))
+ end
+
def test_acronyms
ActiveSupport::Inflector.inflections do |inflect|
inflect.acronym("API")