Sha256: 0a0a61a784f709799c940c2adfbd6e1e1623ef354077ee2602a8f924aa454c8d

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'
require 'apartment/elevators/host_hash'

describe Apartment::Elevators::HostHash do

  subject(:elevator){ Apartment::Elevators::HostHash.new(Proc.new{}, 'example.com' => 'example_tenant') }

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

    it "raises DatabaseNotFound exception if there is no host" do
      request = ActionDispatch::Request.new('HTTP_HOST' => '')
      expect { elevator.parse_tenant_name(request) }.to raise_error(Apartment::DatabaseNotFound)
    end

    it "raises DatabaseNotFound exception if there is no database associated to current host" do
      request = ActionDispatch::Request.new('HTTP_HOST' => 'example2.com')
      expect { elevator.parse_tenant_name(request) }.to raise_error(Apartment::DatabaseNotFound)
    end
  end

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
apartment-0.26.1 spec/unit/elevators/host_hash_spec.rb
apartment-0.26.0 spec/unit/elevators/host_hash_spec.rb
apartment-0.25.2 spec/unit/elevators/host_hash_spec.rb
apartment-0.25.1 spec/unit/elevators/host_hash_spec.rb
apartment-0.25.0 spec/unit/elevators/host_hash_spec.rb