<commit_before>require 'spec_helper'

describe ClicksController do

  context 'create' do

    context 'missing params' do
      it 'raises an error without the url param' do
        expect { xhr :get, :track, post_id: 123 }.to raise_error(ActionController::ParameterMissing)
      end

      it "redirects to the url even without the topic_id or post_id params" do
        xhr :get, :track, url: 'http://google.com'
        expect(response).not_to be_redirect
      end
    end

    context 'correct params' do
      let(:url) { "http://discourse.org" }

      before { request.stubs(:remote_ip).returns('192.168.0.1') }

      context "with a made up url" do
        it "doesn't redirect" do
          TopicLinkClick.expects(:create_from).returns(nil)
          xhr :get, :track, url: 'http://discourse.org', post_id: 123
          expect(response).not_to be_redirect
        end
      end

      context "with a query string" do
        it "redirects" do<commit_msg>correct spec<commit_after>require 'spec_helper'

describe ClicksController do

  context 'create' do

    context 'missing params' do
      it 'raises a 404 without the url param' do
        xhr :get, :track, post_id: 123
        expect(response).to be_not_found
      end

      it "redirects to the url even without the topic_id or post_id params" do
        xhr :get, :track, url: 'http://google.com'
        expect(response).not_to be_redirect
      end
    end

    context 'correct params' do
      let(:url) { "http://discourse.org" }

      before { request.stubs(:remote_ip).returns('192.168.0.1') }

      context "with a made up url" do
        it "doesn't redirect" do
          TopicLinkClick.expects(:create_from).returns(nil)
          xhr :get, :track, url: 'http://discourse.org', post_id: 123
          expect(response).not_to be_redirect
        end
      end

      context "with a query string" do
        it "redirects" do
{'fraction_non_alphanumeric': 0.1003659174072138, 'fraction_numerical': 0.01620491374803973, 'mean_word_length': 2.5054945054945055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6635370', 'n_tokens_mistral': 622, 'n_tokens_neox': 576, 'n_words': 183}