From a4f2ba8fb3c46ef9f7e31725849efdcb1a22c72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Cig=C3=A1nek?= Date: Fri, 12 Sep 2008 14:45:11 +0200 Subject: Modified ActiveSupport::Inflector#parameterize with code from slugalizer (http://github.com/henrik/slugalizer) Handles trailing and leading slashes, and squashes repeated separators into a single character. Signed-off-by: Michael Koziarski [#1034 state:committed] --- activesupport/test/inflector_test.rb | 6 ++++++ activesupport/test/inflector_test_cases.rb | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index f304844e82..d30852c013 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -104,6 +104,12 @@ class InflectorTest < Test::Unit::TestCase end end + def test_parameterize_with_custom_separator + StringToParameterized.each do |some_string, parameterized_string| + assert_equal(parameterized_string.gsub('-', '_'), ActiveSupport::Inflector.parameterize(some_string, '_')) + end + end + def test_classify ClassNameToTableName.each do |class_name, table_name| assert_equal(class_name, ActiveSupport::Inflector.classify(table_name)) diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index 8057809dbd..fc7a35f859 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -147,7 +147,10 @@ module InflectorTestCases "Random text with *(bad)* characters" => "random-text-with-bad-characters", "Malmö" => "malmo", "Garçons" => "garcons", - "Allow_Under_Scores" => "allow_under_scores" + "Allow_Under_Scores" => "allow_under_scores", + "Trailing bad characters!@#" => "trailing-bad-characters", + "!@#Leading bad characters" => "leading-bad-characters", + "Squeeze separators" => "squeeze-separators" } UnderscoreToHuman = { -- cgit v1.2.3