<commit_before>require 'spec_helper'

describe CASino::ServiceRule do
  describe '.allowed?' do
    context 'with an empty table' do
      ['https://www.example.org/', 'http://www.google.com/'].each do |service_url|
        it "allows access to #{service_url}" do
          described_class.allowed?(service_url).should == true
        end
      end
    end

    context 'with a regex rule' do
      before(:each) do
        FactoryGirl.create :service_rule, :regex, url: '^https://.*'
      end

      ['https://www.example.org/', 'https://www.google.com/'].each do |service_url|
        it "allows access to #{service_url}" do
          described_class.allowed?(service_url).should == true
        end
      end

      ['http://www.example.org/', 'http://www.google.com/'].each do |service_url|
        it "does not allow access to #{service_url}" do
          described_class.allowed?(service_url).should == false
        end
      end
    end

    context 'with many regex rules' do
      before(:each) do
        100.times do |counter|
          FactoryGirl.create :service_rule, :regex, url: "^https://www#{counter}.example.com"
        end
      end

      let(:service_url) { 'https://www111.example.com/bla' }

      it 'does not take too long to check a denied service' do
        start = Time.now
        described_class.allowed?(service_url).should == false
        (Time.now - start).should < 0.1
      end
    end

    context 'with a non-regex rule' do
      before(:each) do
        FactoryGirl.create :service_rule, url: 'https://www.google.com/foo'
      end

      ['https://www.google.com/foo'].each do |service_url|
        it "allows access to #{service_url}" do
          described_class.allowed?(service_url).should == true
        end
      end

      ['https://www.example.org/', 'http://www.example.org/', 'https://www.google.com/test'].each do |service_url|
        it "does not allow access to #{service_url}" do
          described_class.allowed?(service_url).should == false
        end
      end
    end
  end
end<commit_msg>Travis is too slow<commit_after>require 'spec_helper'

describe CASino::ServiceRule do
  describe '.allowed?' do
    context 'with an empty table' do
      ['https://www.example.org/', 'http://www.google.com/'].each do |service_url|
        it "allows access to #{service_url}" do
          described_class.allowed?(service_url).should == true
        end
      end
    end

    context 'with a regex rule' do
      before(:each) do
        FactoryGirl.create :service_rule, :regex, url: '^https://.*'
      end

      ['https://www.example.org/', 'https://www.google.com/'].each do |service_url|
        it "allows access to #{service_url}" do
          described_class.allowed?(service_url).should == true
        end
      end

      ['http://www.example.org/', 'http://www.google.com/'].each do |service_url|
        it "does not allow access to #{service_url}" do
          described_class.allowed?(service_url).should == false
        end
      end
    end

    context 'with many regex rules' do
      before(:each) do
        100.times do |counter|
          FactoryGirl.create :service_rule, :regex, url: "^https://www#{counter}.example.com"
        end
      end

      let(:service_url) { 'https://www111.example.com/bla' }

      it 'does not take too long to check a denied service' do
        start = Time.now
        described_class.allowed?(service_url).should == false
        (Time.now - start).should < 1.0
      end
    end

    context 'with a non-regex rule' do
      before(:each) do
        FactoryGirl.create :service_rule, url: 'https://www.google.com/foo'
      end

      ['https://www.google.com/foo'].each do |service_url|
        it "allows access to #{service_url}" do
          described_class.allowed?(service_url).should == true
        end
      end

      ['https://www.example.org/', 'http://www.example.org/', 'https://www.google.com/test'].each do |service_url|
        it "does not allow access to #{service_url}" do
          described_class.allowed?(service_url).should == false
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1340782122905028, 'fraction_numerical': 0.0038863249939276173, 'mean_word_length': 2.2996794871794872, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 20, 'lorem ipsum': 0, 'www.': 26, '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': '4017307', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1223, 'n_words': 324}