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.

39 lines
1.1 KiB

  1. require 'rails_helper'
  2. RSpec.describe Formatter do
  3. let(:account) { Fabricate(:account, username: 'alice') }
  4. let(:local_status) { Fabricate(:status, text: 'Hello world http://google.com', account: account) }
  5. let(:remote_status) { Fabricate(:status, text: '<script>alert("Hello")</script> Beep boop', uri: 'beepboop', account: account) }
  6. describe '#format' do
  7. subject { Formatter.instance.format(local_status) }
  8. it 'returns a string' do
  9. expect(subject).to be_a String
  10. end
  11. it 'contains plain text' do
  12. expect(subject).to match('Hello world')
  13. end
  14. it 'contains a link' do
  15. expect(subject).to match('<a rel="nofollow noopener" target="_blank" href="http://google.com">google.com</a>')
  16. end
  17. end
  18. describe '#reformat' do
  19. subject { Formatter.instance.format(remote_status) }
  20. it 'returns a string' do
  21. expect(subject).to be_a String
  22. end
  23. it 'contains plain text' do
  24. expect(subject).to match('Beep boop')
  25. end
  26. it 'does not contain scripts' do
  27. expect(subject).to_not match('<script>alert("Hello")</script>')
  28. end
  29. end
  30. end