Sha256: 7b14e4e150e32250400633c26ae9ce79fb00ecf7c13c5ef5eeaf341aca3073bc

Contents?: true

Size: 984 Bytes

Versions: 9

Compression:

Stored size: 984 Bytes

Contents

require 'spec_helper'
require 'apartment/elevators/domain'

describe Apartment::Elevators::Domain do

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

  describe "#parse_tenant_name" do
    it "parses the host for a domain name" do
      request = ActionDispatch::Request.new('HTTP_HOST' => 'example.com')
      expect(elevator.parse_tenant_name(request)).to eq('example')
    end

    it "ignores a www prefix and domain suffix" do
      request = ActionDispatch::Request.new('HTTP_HOST' => 'www.example.bc.ca')
      expect(elevator.parse_tenant_name(request)).to eq('example')
    end

    it "returns nil if there is no host" do
      request = ActionDispatch::Request.new('HTTP_HOST' => '')
      expect(elevator.parse_tenant_name(request)).to be_nil
    end
  end

  describe "#call" do
    it "switches to the proper tenant" do
      expect(Apartment::Tenant).to receive(:switch).with('example')

      elevator.call('HTTP_HOST' => 'www.example.com')
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
ros-apartment-2.3.0 spec/unit/elevators/domain_spec.rb
ros-apartment-2.3.0.alpha2 spec/unit/elevators/domain_spec.rb
ros-apartment-2.3.0.alpha1 spec/unit/elevators/domain_spec.rb
apartment-2.2.1 spec/unit/elevators/domain_spec.rb
apartment-2.2.0 spec/unit/elevators/domain_spec.rb
apartment-2.1.0 spec/unit/elevators/domain_spec.rb
apartment-2.0.0 spec/unit/elevators/domain_spec.rb
apartment-1.2.0 spec/unit/elevators/domain_spec.rb
apartment-1.1.0 spec/unit/elevators/domain_spec.rb