<commit_before>require 'spec_helper'

require 'rack/test'
require 'bouncer'

describe Bouncer do
  include Rack::Test::Methods

  let(:app) { subject }
  let(:host_class) { double 'Host' }
  let(:host) { double 'host' }
  let(:hostname) { 'example.com' }
  let(:path) { '/' }
  let(:url) { "http://#{hostname}#{path}" }
  let(:path_hash) { double }
  let(:site) { double 'site' }
  let(:mappings) { double 'mappings' }
  let(:mapping) { double 'mapping' }

  before(:each) do
    stub_const 'Host', host_class

    host_class.stub find_by: host
    Digest::SHA1.stub hexdigest: path_hash
    host.stub site: site
    site.stub mappings: mappings
    mappings.stub find_by: mapping
    mapping.stub http_status: status_code.to_s
  end

  shared_examples 'a redirector' do
    it 'should respond to requests' do
      expect { get url }.to_not raise_error
    end

    it 'should find the right host' do
      host_class.should_receive(:find_by).with(host: hostname)
      get url
    end

    it 'should hash the path' do
      Digest::SHA1.should_receive(:hexdigest).with(path)
      get url
    end

    it 'should get the host\'s site' do
      host.should_receive(:site).with(no_args)
      get url
    end

    it 'should get the site\'s mappings' do
      site.should_receive(:mappings).with(no_args)
      get url
    end

    it 'should find the right mapping' do
      mappings.should_receive(:find_by).with(path_hash: path_hash)
      get url
    end

    it 'should get the mapping\'s status code' do<commit_msg>Don't bother naming the Host double<commit_after>require 'spec_helper'

require 'rack/test'
require 'bouncer'

describe Bouncer do
  include Rack::Test::Methods

  let(:app) { subject }
  let(:host) { double 'host' }
  let(:hostname) { 'example.com' }
  let(:path) { '/' }
  let(:url) { "http://#{hostname}#{path}" }
  let(:path_hash) { double }
  let(:site) { double 'site' }
  let(:mappings) { double 'mappings' }
  let(:mapping) { double 'mapping' }

  before(:each) do
    stub_const 'Host', double
    Host.stub find_by: host
    Digest::SHA1.stub hexdigest: path_hash
    host.stub site: site
    site.stub mappings: mappings
    mappings.stub find_by: mapping
    mapping.stub http_status: status_code.to_s
  end

  shared_examples 'a redirector' do
    it 'should respond to requests' do
      expect { get url }.to_not raise_error
    end

    it 'should find the right host' do
      Host.should_receive(:find_by).with(host: hostname)
      get url
    end

    it 'should hash the path' do
      Digest::SHA1.should_receive(:hexdigest).with(path)
      get url
    end

    it 'should get the host\'s site' do
      host.should_receive(:site).with(no_args)
      get url
    end

    it 'should get the site\'s mappings' do
      site.should_receive(:mappings).with(no_args)
      get url
    end

    it 'should find the right mapping' do
      mappings.should_receive(:find_by).with(path_hash: path_hash)
      get url
    end

    it 'should get the mapping\'s status code' do
{'fraction_non_alphanumeric': 0.1148738379814077, 'fraction_numerical': 0.0013280212483399733, 'mean_word_length': 3.060646900269542, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '5860382', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1010, 'n_words': 279}