Skip to content

Commit

Permalink
Fix example for nicknames
Browse files Browse the repository at this point in the history
  • Loading branch information
rmm5t committed Nov 24, 2017
1 parent 4f343cf commit 0655ac8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class User < ActiveRecord::Base
strip_attributes only: :phone, regex: /[^0-9]/

# Strip off all spaces and keep only alphabetic and numeric characters
strip_attributes only: :nick_name, regex: /[^[:alnum:]\S]/
strip_attributes only: :nickname, regex: /[^[:alnum:]_-]/

# Remove trailing whitespace from a multi-line string
strip_attributes only: :code, regex: /[[:blank:]]+$/)
Expand Down
5 changes: 5 additions & 0 deletions test/strip_attributes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ def test_should_strip_regex
assert_equal "abc", StripAttributes.strip("^%&*abc ^ ", regex: /[\^\%&\*]/)
end

def test_should_keep_only_alphanumerics
nickname = " funky BAT-2009"
assert_equal "funkyBAT-2009", StripAttributes.strip(nickname, regex: /[^[:alnum:]_-]/)
end

def test_should_strip_trailing_whitespace
messy_code =
"const hello = (name) => { \n" +
Expand Down

0 comments on commit 0655ac8

Please sign in to comment.