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.

53 lines
1.9 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' do
  6. status = double(local?: false)
  7. subject.validate(status)
  8. expect(status).not_to receive(:errors)
  9. end
  10. it 'does not add errors onto local reblogs' do
  11. status = double(local?: false, reblog?: true)
  12. subject.validate(status)
  13. expect(status).not_to receive(:errors)
  14. end
  15. it 'adds an error when content warning is over 500 characters' do
  16. status = double(spoiler_text: 'a' * 520, text: '', errors: double(add: nil), local?: true, reblog?: false)
  17. subject.validate(status)
  18. expect(status.errors).to have_received(:add)
  19. end
  20. it 'adds an error when text is over 500 characters' do
  21. status = double(spoiler_text: '', text: 'a' * 520, errors: double(add: nil), local?: true, reblog?: false)
  22. subject.validate(status)
  23. expect(status.errors).to have_received(:add)
  24. end
  25. it 'adds an error when text and content warning are over 500 characters total' do
  26. status = double(spoiler_text: 'a' * 250, text: 'b' * 251, errors: double(add: nil), local?: true, reblog?: false)
  27. subject.validate(status)
  28. expect(status.errors).to have_received(:add)
  29. end
  30. it 'counts URLs as 23 characters flat' do
  31. text = ('a' * 476) + " http://#{'b' * 30}.com/example"
  32. status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
  33. subject.validate(status)
  34. expect(status.errors).to_not have_received(:add)
  35. end
  36. it 'counts only the front part of remote usernames' do
  37. text = ('a' * 475) + " @alice@#{'b' * 30}.com"
  38. status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
  39. subject.validate(status)
  40. expect(status.errors).to_not have_received(:add)
  41. end
  42. end
  43. end