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.

35 lines
1.6 KiB

  1. require 'rails_helper'
  2. RSpec.describe FetchLinkCardService do
  3. subject { FetchLinkCardService.new }
  4. before do
  5. stub_request(:head, 'http://example.xn--fiqs8s/').to_return(status: 200, headers: { 'Content-Type' => 'text/html' })
  6. stub_request(:get, 'http://example.xn--fiqs8s/').to_return(request_fixture('idn.txt'))
  7. stub_request(:head, 'https://github.com/qbi/WannaCry').to_return(status: 404)
  8. subject.call(status)
  9. end
  10. context 'in a local status' do
  11. context do
  12. let(:status) { Fabricate(:status, text: 'Check out http://example.中国') }
  13. it 'works with IDN URLs' do
  14. expect(a_request(:get, 'http://example.xn--fiqs8s/')).to have_been_made.at_least_once
  15. end
  16. end
  17. end
  18. context 'in a remote status' do
  19. let(:status) { Fabricate(:status, uri: 'abc', text: 'Habt ihr ein paar gute Links zu #<span class="tag"><a href="https://quitter.se/tag/wannacry" target="_blank" rel="tag noopener" title="https://quitter.se/tag/wannacry">Wannacry</a></span> herumfliegen? Ich will mal unter <br> <a href="https://github.com/qbi/WannaCry" target="_blank" rel="noopener" title="https://github.com/qbi/WannaCry">https://github.com/qbi/WannaCry</a> was sammeln. !<a href="http://sn.jonkman.ca/group/416/id" target="_blank" rel="noopener" title="http://sn.jonkman.ca/group/416/id">security</a>&nbsp;') }
  20. it 'parses out URLs' do
  21. expect(a_request(:head, 'https://github.com/qbi/WannaCry')).to have_been_made.at_least_once
  22. end
  23. it 'ignores URLs to hashtags' do
  24. expect(a_request(:head, 'https://quitter.se/tag/wannacry')).to_not have_been_made
  25. end
  26. end
  27. end