Sha256: 2e554fe09d0d867d4f8c0c1a408fc159ae01cfefda1df7217eec695109a9a6bb

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'
require 'apartment/elevators/subdomain'

describe Apartment::Elevators::Subdomain do

  subject(:elevator){ described_class.new(Proc.new{}) }

  describe "#parse_tenant_name" do
    context "assuming tld_length of 1" do
      it "should parse subdomain" do
        request = ActionDispatch::Request.new('HTTP_HOST' => 'foo.bar.com')
        elevator.parse_tenant_name(request).should == 'foo'
      end

      it "should return nil when no subdomain" do
        request = ActionDispatch::Request.new('HTTP_HOST' => 'bar.com')
        elevator.parse_tenant_name(request).should be_nil
      end
    end

    context "assuming tld_length of 2" do
      before do
        Apartment.configure do |config|
          config.tld_length = 2
        end
      end

      it "should parse subdomain in the third level domain" do
        request = ActionDispatch::Request.new('HTTP_HOST' => 'foo.bar.co.uk')
        elevator.parse_tenant_name(request).should == "foo"
      end

      it "should return nil when no subdomain in the third level domain" do
        request = ActionDispatch::Request.new('HTTP_HOST' => 'bar.co.uk')
        elevator.parse_tenant_name(request).should be_nil
      end
    end
  end

  describe "#call" do
    it "switches to the proper tenant" do
      Apartment::Database.should_receive(:switch).with('tenant1')
      elevator.call('HTTP_HOST' => 'tenant1.example.com')
    end

    it "ignores excluded subdomains" do
      described_class.excluded_subdomains = %w{foo}

      Apartment::Database.should_not_receive(:switch)

      elevator.call('HTTP_HOST' => 'foo.bar.com')

      described_class.excluded_subdomains = nil
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
apartment-0.24.3 spec/unit/elevators/subdomain_spec.rb
apartment-0.24.2 spec/unit/elevators/subdomain_spec.rb
apartment-0.24.1 spec/unit/elevators/subdomain_spec.rb
apartment-0.24.0 spec/unit/elevators/subdomain_spec.rb