<commit_before>require 'spec_helper'

describe ApartmentSpree::Elevators::Subdomain do
  before do
    Apartment::Database.drop('tenant_name') rescue "We don't care if this fails"
    Apartment::Database.create('tenant_name')
  end

  context 'schema switching' do
    let(:app) { double 'app', call: true }

    context 'with subdomain' do
      let(:subdomain) { 'this-is-a-sub' }

      it 'Apartment::Database receives the correctly parsed tenant_schema' do
        expect(Apartment::Database).to receive(:switch)
          .with(subdomain.gsub('-','_'))

        ApartmentSpree::Elevators::Subdomain.new(app).call env_domain(subdomain)
      end

      it 'Apartment::Database is set to nil after a failed schema switch' do
        expect(app).to_not receive(:call)
        ApartmentSpree::Elevators::Subdomain.new(app).call env_domain(subdomain)
      end

      it 'assigns the requests tenant' do
        expect(Apartment::Database).to receive(:switch).with('tenant_name')
        expect(app).to receive(:call)
        ApartmentSpree::Elevators::Subdomain.new(app).call(
          env_domain('tenant-name')
        )
      end
    end

    context 'without a subdomain' do
      it 'does not receive .process_request' do
        elevator = ApartmentSpree::Elevators::Subdomain.new(app)
        expect(elevator).to_not receive(:process_request)
        elevator.call Rack::MockRequest.env_for("http://example.com")
      end
    end
  end

  def env_domain(subdomain)
    Rack::MockRequest.env_for "http://#{subdomain}.example.com"
  end
end<commit_msg>fixing double quote violation<commit_after>require 'spec_helper'

describe ApartmentSpree::Elevators::Subdomain do
  before do
    Apartment::Database.drop('tenant_name') rescue "We don't care if this fails"
    Apartment::Database.create('tenant_name')
  end

  context 'schema switching' do
    let(:app) { double 'app', call: true }

    context 'with subdomain' do
      let(:subdomain) { 'this-is-a-sub' }

      it 'Apartment::Database receives the correctly parsed tenant_schema' do
        expect(Apartment::Database).to receive(:switch)
          .with(subdomain.gsub('-','_'))

        ApartmentSpree::Elevators::Subdomain.new(app).call env_domain(subdomain)
      end

      it 'Apartment::Database is set to nil after a failed schema switch' do
        expect(app).to_not receive(:call)
        ApartmentSpree::Elevators::Subdomain.new(app).call env_domain(subdomain)
      end

      it 'assigns the requests tenant' do
        expect(Apartment::Database).to receive(:switch).with('tenant_name')
        expect(app).to receive(:call)
        ApartmentSpree::Elevators::Subdomain.new(app).call(
          env_domain('tenant-name')
        )
      end
    end

    context 'without a subdomain' do
      it 'does not receive .process_request' do
        elevator = ApartmentSpree::Elevators::Subdomain.new(app)
        expect(elevator).to_not receive(:process_request)
        elevator.call Rack::MockRequest.env_for('http://example.com')
      end
    end
  end

  def env_domain(subdomain)
    Rack::MockRequest.env_for "http://#{subdomain}.example.com"
  end
end
{'fraction_non_alphanumeric': 0.11798469387755102, 'fraction_numerical': 0.0, 'mean_word_length': 3.381284916201117, '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': '7233243', 'n_tokens_mistral': 965, 'n_tokens_neox': 954, 'n_words': 208}