html_aware_formatter_spec.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. require 'rails_helper'
  2. RSpec.describe HtmlAwareFormatter do
  3. describe '#to_s' do
  4. subject { described_class.new(text, local).to_s }
  5. context 'when local' do
  6. let(:local) { true }
  7. let(:text) { 'Foo bar' }
  8. it 'returns formatted text' do
  9. is_expected.to eq '<p>Foo bar</p>'
  10. end
  11. end
  12. context 'when remote' do
  13. let(:local) { false }
  14. context 'given plain text' do
  15. let(:text) { 'Beep boop' }
  16. it 'keeps the plain text' do
  17. is_expected.to include 'Beep boop'
  18. end
  19. end
  20. context 'given text containing script tags' do
  21. let(:text) { '<script>alert("Hello")</script>' }
  22. it 'strips the scripts' do
  23. is_expected.to_not include '<script>alert("Hello")</script>'
  24. end
  25. end
  26. context 'given text containing malicious classes' do
  27. let(:text) { '<span class="mention status__content__spoiler-link">Show more</span>' }
  28. it 'strips the malicious classes' do
  29. is_expected.to_not include 'status__content__spoiler-link'
  30. end
  31. end
  32. end
  33. end
  34. end