File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed
lib/active_support/core_ext/string Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -102,8 +102,8 @@ def demodulize
102
102
#
103
103
# <%= link_to(@person.name, person_path %>
104
104
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
105
- def parameterize
106
- Inflector . parameterize ( self )
105
+ def parameterize ( sep = '-' )
106
+ Inflector . parameterize ( self , sep )
107
107
end
108
108
109
109
# Creates the name of a table like Rails does for models to table names. This method
Original file line number Diff line number Diff line change @@ -77,6 +77,24 @@ def test_classify
77
77
end
78
78
end
79
79
80
+ def test_string_parameterized_normal
81
+ StringToParameterized . each do |normal , slugged |
82
+ assert_equal ( normal . parameterize , slugged )
83
+ end
84
+ end
85
+
86
+ def test_string_parameterized_no_separator
87
+ StringToParameterizeWithNoSeparator . each do |normal , slugged |
88
+ assert_equal ( normal . parameterize ( '' ) , slugged )
89
+ end
90
+ end
91
+
92
+ def test_string_parameterized_underscore
93
+ StringToParameterizeWithUnderscore . each do |normal , slugged |
94
+ assert_equal ( normal . parameterize ( '_' ) , slugged )
95
+ end
96
+ end
97
+
80
98
def test_humanize
81
99
UnderscoreToHuman . each do |underscore , human |
82
100
assert_equal ( human , underscore . humanize )
Original file line number Diff line number Diff line change @@ -154,6 +154,22 @@ module InflectorTestCases
154
154
"Squeeze separators" => "squeeze-separators"
155
155
}
156
156
157
+ StringToParameterizeWithNoSeparator = {
158
+ "Donald E. Knuth" => "donaldeknuth" ,
159
+ "Random text with *(bad)* characters" => "randomtextwithbadcharacters" ,
160
+ "Trailing bad characters!@#" => "trailingbadcharacters" ,
161
+ "!@#Leading bad characters" => "leadingbadcharacters" ,
162
+ "Squeeze separators" => "squeezeseparators"
163
+ }
164
+
165
+ StringToParameterizeWithUnderscore = {
166
+ "Donald E. Knuth" => "donald_e_knuth" ,
167
+ "Random text with *(bad)* characters" => "random_text_with_bad_characters" ,
168
+ "Trailing bad characters!@#" => "trailing_bad_characters" ,
169
+ "!@#Leading bad characters" => "leading_bad_characters" ,
170
+ "Squeeze separators" => "squeeze_separators"
171
+ }
172
+
157
173
# Ruby 1.9 doesn't do Unicode normalization yet.
158
174
if RUBY_VERSION >= '1.9'
159
175
StringToParameterizedAndNormalized = {
You can’t perform that action at this time.
0 commit comments