You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.0 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe NoteLengthValidator do
  4. subject { NoteLengthValidator.new(attributes: { note: true }, maximum: 500) }
  5. describe '#validate' do
  6. it 'adds an error when text is over 500 characters' do
  7. text = 'a' * 520
  8. account = double(note: text, errors: double(add: nil))
  9. subject.validate_each(account, 'note', text)
  10. expect(account.errors).to have_received(:add)
  11. end
  12. it 'counts URLs as 23 characters flat' do
  13. text = ('a' * 476) + " http://#{'b' * 30}.com/example"
  14. account = double(note: text, errors: double(add: nil))
  15. subject.validate_each(account, 'note', text)
  16. expect(account.errors).to_not have_received(:add)
  17. end
  18. it 'does not count non-autolinkable URLs as 23 characters flat' do
  19. text = ('a' * 476) + "http://#{'b' * 30}.com/example"
  20. account = double(note: text, errors: double(add: nil))
  21. subject.validate_each(account, 'note', text)
  22. expect(account.errors).to have_received(:add)
  23. end
  24. end
  25. end