From bd4161f48c746851a6ff2f3ab47c2b915cdebf38 Mon Sep 17 00:00:00 2001 From: Miha Filej Date: Thu, 25 Sep 2008 16:19:18 +0200 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 | 14 ++++++++++++++ 2 files changed, 16 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 b086c95..03f7370 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -71,6 +71,20 @@ class StringInflectionsTest < Test::Unit::TestCase end end + uses_mocha "parameterize" do + def test_parameterize_with_default_separator + str = "parameterize me" + ActiveSupport::Inflector.expects(:parameterize).with(str) + str.parameterize() + end + + def test_parameterize_with_custom_separator + str = "parameterize me" + ActiveSupport::Inflector.expects(:parameterize).with(str, '_') + str.parameterize('_') + end + end + def test_classify ClassNameToTableName.each do |class_name, table_name| assert_equal(class_name, table_name.classify) -- 1.6.0