djsun-context 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +1 -0
- data/context.gemspec +1 -1
- data/lib/context/core_ext/string.rb +1 -1
- data/lib/context/version.rb +1 -1
- data/test/test_core_ext.rb +8 -4
- metadata +1 -1
data/Manifest.txt
CHANGED
data/context.gemspec
CHANGED
@@ -2,7 +2,7 @@ class String
|
|
2
2
|
# Replaces spaces and tabs with _ so we can use the string as a method name
|
3
3
|
# Also replace dangerous punctuation
|
4
4
|
def to_method_name
|
5
|
-
self.downcase.gsub(/[\s:',\.~;!#=\(\)
|
5
|
+
self.downcase.gsub(/[\s:',\.~;!#=\(\)&\?]+/, '_')
|
6
6
|
end
|
7
7
|
|
8
8
|
# Borrowed from +camelize+ in ActiveSupport
|
data/lib/context/version.rb
CHANGED
data/test/test_core_ext.rb
CHANGED
@@ -3,19 +3,23 @@ require File.dirname(__FILE__) + '/test_helper.rb'
|
|
3
3
|
class TestCoreExt < Test::Unit::TestCase
|
4
4
|
context "A string" do
|
5
5
|
it "should be converted to method name" do
|
6
|
-
|
6
|
+
assert_equal "this_is_fun", "this is fun".to_method_name
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should be downcased when converted" do
|
10
|
-
|
10
|
+
assert_equal "this_is_a_blast", "THIS is A BlASt".to_method_name
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should change spaces to _" do
|
14
|
-
|
14
|
+
assert_equal "this_has_been_great", "This has been great".to_method_name
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should change dangerous punctuation to _" do
|
18
|
-
|
18
|
+
assert_equal "no_really_this_was_good_", "No, really; this was #good!".to_method_name
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should change ? to _" do
|
22
|
+
assert_equal "are_you_sure_yes_", "Are you sure? Yes.".to_method_name
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|