3 class InvalidCharsValidatable
4 include ActiveModel::Validations
5 validates :chars, :characters => true
9 class InvalidUrlCharsValidatable
10 include ActiveModel::Validations
11 validates :chars, :characters => { :url_safe => true }
15 class CharactersValidatorTest < ActiveSupport::TestCase
16 include Rails::Dom::Testing::Assertions::SelectorAssertions
18 def test_with_valid_chars
19 c = InvalidCharsValidatable.new
21 valid = ["Name.", "'me", "he\"", "<hr>", "*ho", "\"help\"@",
22 "vergrößern", "ルシステムにも対応します", "輕觸搖晃的遊戲", "/;.,?%#"]
26 assert_predicate c, :valid?, "'#{v}' should be valid"
30 def test_with_invalid_chars
31 c = InvalidCharsValidatable.new
33 invalid = ["\x7f<hr/>", "test@example.com\x0e-", "s/\x1ff", "aa/\ufffe",
34 "aa\x0b-,", "aa?\x08", "/;\uffff.,?", "\x00-も対応します/", "\x0c#ping",
35 "foo\x1fbar", "foo\x7fbar", "foo\ufffebar", "foo\uffffbar"]
39 assert_not c.valid?, "'#{v}' should not be valid"
43 def test_with_valid_url_chars
44 c = InvalidUrlCharsValidatable.new
46 valid = ["Name", "'me", "he\"", "<hr>", "*ho", "\"help\"@",
47 "vergrößern", "ルシステムにも対応します", "輕觸搖晃的遊戲"]
51 assert_predicate c, :valid?, "'#{v}' should be valid"
55 def test_with_invalid_url_chars
56 c = InvalidUrlCharsValidatable.new
58 invalid = ["Name.", "you;me", "he\"#", "<hr/>", "50%", "good?",
59 "vergrößern,deutsche", "ルシステムに;.も対応します", "輕觸搖/晃的遊戲", "/;.,?%#"]
63 assert_not c.valid?, "'#{v}' should not be valid"