status_length_validator_spec.rb 1.6 KB

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