<commit_before>require_relative '../../app/classes/fact_url'
require 'cgi'
require 'uri'

describe FactUrl do

  before do
    stub_const 'FactlinkUI::Application', Class.new
    config = double core_url:  'https://site.com',
                    proxy_url: 'http://proxy.com'
    FactlinkUI::Application.stub(config: config)
  end

  describe '.fact_url' do
    it 'returns the correct url' do
      fact = double id: '1'

      fact_url = FactUrl.new fact

      expect(fact_url.fact_url)
        .to eq 'https://site.com/facts/1'
    end
  end

  describe '.friendly_fact_url' do
    it 'returns the correct url' do
      fact = double id: '2'

      fact_url = FactUrl.new fact

      expect(fact_url.friendly_fact_url)
        .to eq "https://site.com/f/2"
    end
  end

  describe '.proxy_open_url' do
    it 'returns the correct url' do
      fact = double id: '3', site_url: 'http://sciencedaily.com'

      fact_url = FactUrl.new fact

      expect(fact_url.proxy_open_url)
        .to eq 'http://proxy.com/?url=http%3A%2F%2Fsciencedaily.com#factlink-open-3'
    end
  end

  describe '.sharing_url' do
    it 'returns the proxy_open_url' do
      fact = double id: '3', site_url: 'http://sciencedaily.com'

      fact_url = FactUrl.new fact

      expect(fact_url.sharing_url)
        .to eq 'http://proxy.com/?url=http%3A%2F%2Fsciencedaily.com#factlink-open-3'
    end
  end

  describe 'xss protection' do
    describe '.friendly_fact_url' do
      it 'does not contain tags' do
        fact = double id: '22', to_s: 'this<script>funky stuff'

        fact_url = FactUrl.new fact

        expect(fact_url.friendly_fact_url)
          .not_to match '<'
        expect(fact_url.friendly_fact_url)
          .not_to match '>'
      end
      it 'does not escape from quotes' do
        fact = double id: '22', to_s: 'double " single \' quote'

        fact_url = FactUrl.new fact

        expect(fact_url.friendly_fact_url)
          .not_to match "'"
        expect(fact_url.friendly_fact_url)
          .not_to match '"'
      end
    end
  end
end<commit_msg>Test something we actually care about<commit_after>require_relative '../../app/classes/fact_url'
require 'cgi'
require 'uri'

describe FactUrl do

  before do
    stub_const 'FactlinkUI::Application', Class.new
    config = double core_url:  'https://site.com',
                    proxy_url: 'http://proxy.com'
    FactlinkUI::Application.stub(config: config)
  end

  describe '.fact_url' do
    it 'returns the correct url' do
      fact = double id: '1'

      fact_url = FactUrl.new fact

      expect(fact_url.fact_url)
        .to eq 'https://site.com/facts/1'
    end
  end

  describe '.friendly_fact_url' do
    it 'returns the correct url' do
      fact = double id: '2'

      fact_url = FactUrl.new fact

      expect(fact_url.friendly_fact_url)
        .to eq "https://site.com/f/2"
    end
  end

  describe '.proxy_open_url' do
    it 'returns the correct url' do
      fact = double id: '3', site_url: 'http://sciencedaily.com'

      fact_url = FactUrl.new fact

      expect(fact_url.proxy_open_url)
        .to eq 'http://proxy.com/?url=http%3A%2F%2Fsciencedaily.com#factlink-open-3'
    end
  end

  describe '.sharing_url' do
    it 'returns the proxy_open_url' do
      fact = double id: '3', site_url: 'http://sciencedaily.com'

      fact_url = FactUrl.new fact

      expect(fact_url.sharing_url)
        .to eq 'http://proxy.com/?url=http%3A%2F%2Fsciencedaily.com#factlink-open-3'
    end
  end

  describe 'xss protection' do
    describe '.friendly_fact_url' do
      it 'does not contain tags' do
        fact = double id: '22', site_url: 'this<script>funky stuff'

        fact_url = FactUrl.new fact

        expect(fact_url.proxy_open_url)
          .not_to match '<'
        expect(fact_url.proxy_open_url)
          .not_to match '>'
      end
      it 'does not escape from quotes' do
        fact = double id: '22', site_url: 'double " single \' quote'

        fact_url = FactUrl.new fact

        expect(fact_url.proxy_open_url)
          .not_to match "'"
        expect(fact_url.proxy_open_url)
          .not_to match '"'
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11100432484382508, 'fraction_numerical': 0.008649687650168188, 'mean_word_length': 2.3845528455284555, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7467140', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1391, 'n_words': 348}