Sha256: 896ccfc6478312f0c745763788d1c36909f8955c5b54949b6e83820afc0e221c

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

require 'spec_helper'

class Account
  attr_accessor :name
end

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

  if Rails::VERSION::MAJOR < 4
    before_filter :your_method_that_finds_the_current_tenant
  else
    before_action :your_method_that_finds_the_current_tenant
  end

  def your_method_that_finds_the_current_tenant
    current_account = Account.new
    current_account.name = 'account1'
    set_current_tenant(current_account)
  end
end

describe ApplicationController, type: :controller do
  controller do
    def index
      if Rails::VERSION::MAJOR >= 5
        render body: 'custom called'
      else
        render text: 'custom called'
      end
    end
  end

  it 'Finds the correct tenant using the filter command' do
    get :index
    expect(MultiTenant.current_tenant.name).to eq 'account1'
  end
end

if Rails::VERSION::MAJOR >= 5
  class APIApplicationController < ActionController::API
    include Rails.application.routes.url_helpers
    set_current_tenant_through_filter
    before_action :your_method_that_finds_the_current_tenant

    def your_method_that_finds_the_current_tenant
      current_account = Account.new
      current_account.name = 'account1'
      set_current_tenant(current_account)
    end
  end

  describe APIApplicationController, type: :controller do
    controller do
      def index
        render body: 'custom called'
      end
    end

    it 'Finds the correct tenant using the filter command' do
      get :index
      expect(MultiTenant.current_tenant.name).to eq 'account1'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activerecord-multi-tenant-0.4.0 spec/activerecord-multi-tenant/controller_extensions_spec.rb
activerecord-multi-tenant-0.3.4 spec/activerecord-multi-tenant/controller_extensions_spec.rb
activerecord-multi-tenant-0.3.3 spec/activerecord-multi-tenant/controller_extensions_spec.rb