From 143f9db4102c2fcae7a86b98c803630e11309220 Mon Sep 17 00:00:00 2001 From: Miha Filej Date: Thu, 25 Dec 2008 23:17:21 +0100 Subject: [PATCH] Make String#parameterize accept a custom separator --- .../active_support/core_ext/string/inflections.rb | 4 ++-- activesupport/test/core_ext/string_ext_test.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index de99fe5..0e92ce9 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -102,8 +102,8 @@ module ActiveSupport #:nodoc: # # <%= link_to(@person.name, person_path %> # # => Donald E. Knuth - def parameterize - Inflector.parameterize(self) + def parameterize(*sep) + Inflector.parameterize(self, *sep) end # Creates the name of a table like Rails does for models to table names. This method diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index e232bf8..a61bc41 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -71,6 +71,16 @@ class StringInflectionsTest < Test::Unit::TestCase end end + def test_parameterize_with_default_separator + str = "parameterize me" + assert_equal ActiveSupport::Inflector.parameterize(str), str.parameterize + end + + def test_parameterize_with_custom_separator + str = "parameterize me" + assert_equal ActiveSupport::Inflector.parameterize(str, '_'), str.parameterize('_') + end + def test_classify ClassNameToTableName.each do |class_name, table_name| assert_equal(class_name, table_name.classify) -- 1.6.0