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.

51 lines
2.0 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe StatusLengthValidator do
  4. describe '#validate' do
  5. it 'does not add errors onto remote statuses'
  6. it 'does not add errors onto local reblogs'
  7. it 'adds an error when content warning is over MAX_CHARS characters' do
  8. chars = StatusLengthValidator::MAX_CHARS + 1
  9. status = double(spoiler_text: 'a' * chars, text: '', errors: double(add: nil), local?: true, reblog?: false)
  10. subject.validate(status)
  11. expect(status.errors).to have_received(:add)
  12. end
  13. it 'adds an error when text is over MAX_CHARS characters' do
  14. chars = StatusLengthValidator::MAX_CHARS + 1
  15. status = double(spoiler_text: '', text: 'a' * chars, errors: double(add: nil), local?: true, reblog?: false)
  16. subject.validate(status)
  17. expect(status.errors).to have_received(:add)
  18. end
  19. it 'adds an error when text and content warning are over MAX_CHARS characters total' do
  20. chars1 = 20
  21. chars2 = StatusLengthValidator::MAX_CHARS + 1 - chars1
  22. status = double(spoiler_text: 'a' * chars1, text: 'b' * chars2, errors: double(add: nil), local?: true, reblog?: false)
  23. subject.validate(status)
  24. expect(status.errors).to have_received(:add)
  25. end
  26. it 'counts URLs as 23 characters flat' do
  27. chars = StatusLengthValidator::MAX_CHARS - 1 - 23
  28. text = ('a' * chars) + " http://#{'b' * 30}.com/example"
  29. status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
  30. subject.validate(status)
  31. expect(status.errors).to_not have_received(:add)
  32. end
  33. it 'counts only the front part of remote usernames' do
  34. username = '@alice'
  35. chars = StatusLengthValidator::MAX_CHARS - 1 - username.length
  36. text = ('a' * 475) + " #{username}@#{'b' * 30}.com"
  37. status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
  38. subject.validate(status)
  39. expect(status.errors).to_not have_received(:add)
  40. end
  41. end
  42. end