3 class InvalidCharsValidatable
4 include ActiveModel::Validations
6 validates :chars, :characters => true
10 class InvalidUrlCharsValidatable
11 include ActiveModel::Validations
13 validates :chars, :characters => { :url_safe => true }
17 class CharactersValidatorTest < ActiveSupport::TestCase
18 include Rails::Dom::Testing::Assertions::SelectorAssertions
20 def test_with_valid_chars
21 c = InvalidCharsValidatable.new
23 valid = ["Name.", "'me", "he\"", "<hr>", "*ho", "\"help\"@",
24 "vergrößern", "ルシステムにも対応します", "輕觸搖晃的遊戲", "/;.,?%#"]
28 assert_predicate c, :valid?, "'#{v}' should be valid"
32 def test_with_invalid_chars
33 c = InvalidCharsValidatable.new
35 invalid = ["\x7f<hr/>", "test@example.com\x0e-", "s/\x1ff", "aa/\ufffe",
36 "aa\x0b-,", "aa?\x08", "/;\uffff.,?", "\x00-も対応します/", "\x0c#ping",
37 "foo\x1fbar", "foo\x7fbar", "foo\ufffebar", "foo\uffffbar"]
41 assert_not_predicate c, :valid?, "'#{v}' should not be valid"
45 def test_with_valid_url_chars
46 c = InvalidUrlCharsValidatable.new
48 valid = ["Name", "'me", "he\"", "<hr>", "*ho", "\"help\"@",
49 "vergrößern", "ルシステムにも対応します", "輕觸搖晃的遊戲"]
53 assert_predicate c, :valid?, "'#{v}' should be valid"
57 def test_with_invalid_url_chars
58 c = InvalidUrlCharsValidatable.new
60 invalid = ["Name.", "you;me", "he\"#", "<hr/>", "50%", "good?",
61 "vergrößern,deutsche", "ルシステムに;.も対応します", "輕觸搖/晃的遊戲", "/;.,?%#"]
65 assert_not_predicate c, :valid?, "'#{v}' should not be valid"