From 43b48d7441a448ea89742cc7d9638b94039fda6c Mon Sep 17 00:00:00 2001 From: David Calavera Date: Tue, 30 Jun 2009 17:05:08 +0200 Subject: [PATCH] ensure Inflector.camelize works with symbols --- activesupport/lib/active_support/inflector.rb | 2 +- activesupport/test/inflector_test.rb | 6 ++++++ activesupport/test/inflector_test_cases.rb | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb index ff70d6d..92c1de0 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -183,7 +183,7 @@ module ActiveSupport if first_letter_in_uppercase lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } else - lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1] + lower_case_and_underscored_word.to_s.first.downcase + camelize(lower_case_and_underscored_word)[1..-1] end end diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 8c4d831..7d15549 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -202,6 +202,12 @@ class InflectorTest < Test::Unit::TestCase end end + def test_symbol_to_lower_camel + SymbolToLowerCamel.each do |symbol, lower_camel| + assert_equal(lower_camel, ActiveSupport::Inflector.camelize(symbol, false)) + end + end + %w{plurals singulars uncountables humans}.each do |inflection_type| class_eval " def test_clear_#{inflection_type} diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index 584cbff..2fa94b8 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -117,6 +117,13 @@ module InflectorTestCases "area51_controller" => "area51Controller" } + SymbolToLowerCamel = { + :product => 'product', + :special_guest => 'specialGuest', + :application_controller => 'applicationController', + :area51_controller => 'area51Controller' + } + CamelToUnderscoreWithoutReverse = { "HTMLTidy" => "html_tidy", "HTMLTidyGenerator" => "html_tidy_generator", -- 1.6.0.4