]> git.openstreetmap.org Git - rails.git/blob - test/validators/invalid_url_chars_validator_test.rb
Added tests for validators
[rails.git] / test / validators / invalid_url_chars_validator_test.rb
1 require "test_helper"
2
3 class InvalidUrlCharsValidatable
4   include ActiveModel::Validations
5   validates :chars, :invalid_url_chars => true
6   attr_accessor :chars
7 end
8
9 class InvalidUrlCharsValidatorTest < ActiveSupport::TestCase
10   include Rails::Dom::Testing::Assertions::SelectorAssertions
11
12   def test_with_valid_url_chars
13     c = InvalidUrlCharsValidatable.new
14
15     valid = ["\x7f<hr>", "test@examplecom\x0e-", "s\x1ff", "aa\ufffe",
16              "aa\x0b-", "aa\x08", "\uffff::", "\x00-も対応します", "\x0c*ping",
17              "foo\x1fbar", "foo\x7fbar", "foo\ufffebar", "foo\uffffbar"]
18
19     valid.each do |v|
20       c.chars = v
21       assert c.valid?, "'#{v}' should be valid"
22     end
23   end
24
25   def test_with_invalid_url_chars
26     c = InvalidUrlCharsValidatable.new
27
28     invalid = ["Name.", "you;me", "he\"#", "<hr/>", "50%", "good?",
29                "vergrößern,deutsche", "ルシステムに;.も対応します", "輕觸搖/晃的遊戲", "/;.,?%#"]
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