3 class InvalidCharsValidatable
4 include ActiveModel::Validations
5 validates :chars, :invalid_chars => true
9 class InvalidCharsValidatorTest < ActiveSupport::TestCase
10 include Rails::Dom::Testing::Assertions::SelectorAssertions
12 def test_with_valid_chars
13 c = InvalidCharsValidatable.new
15 valid = ["Name.", "'me", "he\"", "<hr>", "*ho", "\"help\"@",
16 "vergrößern", "ルシステムにも対応します", "輕觸搖晃的遊戲", "/;.,?%#"]
20 assert c.valid?, "'#{v}' should be valid"
24 def test_with_invalid_chars
25 c = InvalidCharsValidatable.new
27 invalid = ["\x7f<hr/>", "test@example.com\x0e-", "s/\x1ff", "aa/\ufffe",
28 "aa\x0b-,", "aa?\x08", "/;\uffff.,?", "\x00-も対応します/", "\x0c#ping",
29 "foo\x1fbar", "foo\x7fbar", "foo\ufffebar", "foo\uffffbar"]
33 assert_not c.valid?, "'#{v}' should not be valid"