Module: TenantKit::Testing

Defined in:
lib/tenant_kit/testing.rb

Overview

Opt-in test helpers. Require and include where you need them — they are not loaded by default.

Examples:

RSpec

require "tenant_kit/testing"
RSpec.configure do |config|
  config.include TenantKit::Testing
  config.after { TenantKit::Current.reset }
end

it "does tenant work" do
  as_tenant() { expect(Project.count).to eq(0) }
end

Instance Method Summary collapse

Instance Method Details

#as_tenant(tenant) { ... } ⇒ Object

Runs the block scoped to tenant (alias for TenantKit.with_tenant).

Parameters:

  • tenant (Object)

Yields:

  • the block to run under tenant.

Returns:

  • (Object)

    the block's return value.



21
22
23
# File 'lib/tenant_kit/testing.rb', line 21

def as_tenant(tenant, &block)
  TenantKit.with_tenant(tenant, &block)
end

#without_tenant { ... } ⇒ Object

Runs the block with tenant scoping disabled (alias for TenantKit.without_tenant).

Yields:

  • the block to run unscoped.

Returns:

  • (Object)

    the block's return value.



30
31
32
# File 'lib/tenant_kit/testing.rb', line 30

def without_tenant(&block)
  TenantKit.without_tenant(&block)
end