]> git.openstreetmap.org Git - rails.git/blob - test/validators/invalid_chars_validator_test.rb
Merge leading and trailing whitespace validators
[rails.git] / test / validators / invalid_chars_validator_test.rb
1 require "test_helper"
2
3 class InvalidCharsValidatable
4   include ActiveModel::Validations
5   validates :chars, :invalid_chars => true
6   attr_accessor :chars
7 end
8
9 class InvalidCharsValidatorTest < ActiveSupport::TestCase
10   include Rails::Dom::Testing::Assertions::SelectorAssertions
11
12   def test_with_valid_chars
13     c = InvalidCharsValidatable.new
14
15     valid = ["Name.", "'me", "he\"", "<hr>", "*ho", "\"help\"@",
16              "vergrößern", "ルシステムにも対応します", "輕觸搖晃的遊戲", "/;.,?%#"]
17
18     valid.each do |v|
19       c.chars = v
20       assert c.valid?, "'#{v}' should be valid"
21     end
22   end
23
24   def test_with_invalid_chars
25     c = InvalidCharsValidatable.new
26
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"]
30
31     invalid.each do |v|
32       c.chars = v
33       assert_not c.valid?, "'#{v}' should not be valid"
34     end
35   end
36 end