fix text length validation

completes #64
This commit is contained in:
Mark Moser
2016-09-01 10:37:49 -05:00
parent df1b101aa2
commit a1b93f256d
3 changed files with 36 additions and 27 deletions

View File

@ -25,11 +25,24 @@ class AnswerFormatValidatorTest < ActiveSupport::TestCase
assert_match(/enter.*answer/, obj.errors.messages[:answer][0])
end
test "text should FAIL with more than 1000 charactures" do
test "text should PASS with 999 character" do
obj = AnswerValidatable.new('text')
obj.answer = SecureRandom.urlsafe_base64(1001)
obj.answer = long_string_with_returns
assert obj.valid?
assert obj.errors.messages.empty?
end
test "text should FAIL with more than 1000 character" do
obj = AnswerValidatable.new('text')
obj.answer = long_string_with_returns + " - to long now "
refute obj.valid?
assert_match(/char.*limit.*1000.$/, obj.errors.messages[:answer][0])
end
def long_string_with_returns
# returns 999 chars, after \r is stripped.
"Some rando input\r\n\rYo. Making this up.\r\n" * 27
end
end