3 class TrailingWhitespaceValidatable
4 include ActiveModel::Validations
5 validates :string, :trailing_whitespace => true
9 class TrailingWhitespaceValidatorTest < ActiveSupport::TestCase
10 include Rails::Dom::Testing::Assertions::SelectorAssertions
12 def test_with_trailing_whitespace
13 validator = TrailingWhitespaceValidatable.new
15 strings = [" ", "test ", " ", "test\t", "_test_ "]
19 assert_not validator.valid?, "'#{v}' should not be valid"
23 def test_without_trailing_whitespace
24 validator = TrailingWhitespaceValidatable.new
26 strings = ["test", " test", "tes t", "\ttest", "test.", "test_"]
30 assert validator.valid?, "'#{v}' should be valid"