Sha256: 68b771e72a9edce7a5bb2b784fbd3062d6d3729cf549c68f31103406e8035d19

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

require "spec_helper"

#Setup test specific ApplicationController
class Account; end # this is so the spec will work in isolation

class ApplicationController < ActionController::Base
  include Rails.application.routes.url_helpers
  set_current_tenant_by_subdomain_or_domain
end

# Start testing
describe ApplicationController, :type => :controller do
  controller do
    def index
      render :text => "custom called"
    end
  end

  it 'Finds the correct tenant with a example1.com' do
    @request.host = "example1.com"
    expect(Account).to receive(:where).with({domain: 'example1.com'}) {['account1']}
    get :index
    expect(ActsAsTenant.current_tenant).to eq 'account1'
  end

  it 'Finds the correct tenant with a subdomain.example.com' do
    @request.host = "subdomain.example.com"
    expect(Account).to receive(:where).with({subdomain: 'subdomain'}) {['account1']}
    get :index
    expect(ActsAsTenant.current_tenant).to eq "account1"
  end

  it 'Finds the correct tenant with a www.subdomain.example.com' do
    @request.host = "subdomain.example.com"
    expect(Account).to receive(:where).with({subdomain: 'subdomain'}) {['account1']}
    get :index
    expect(ActsAsTenant.current_tenant).to eq "account1"
  end

  it 'Ignores case when finding tenant by subdomain' do
    @request.host = "SubDomain.example.com"
    expect(Account).to receive(:where).with({subdomain: 'subdomain'}) {['account1']}
    get :index
    expect(ActsAsTenant.current_tenant).to eq "account1"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
acts_as_tenant-0.4.4 spec/acts_as_tenant/tenant_by_subdomain_or_domain.rb
acts_as_tenant-0.4.3 spec/acts_as_tenant/tenant_by_subdomain_or_domain.rb
acts_as_tenant-0.4.2 spec/acts_as_tenant/tenant_by_subdomain_or_domain.rb
acts_as_tenant-0.4.1 spec/acts_as_tenant/tenant_by_subdomain_or_domain.rb
acts_as_tenant-0.4.0 spec/acts_as_tenant/tenant_by_subdomain_or_domain.rb