Sha256: 26d77cd325ceb8b4ce41f745448226edb6eb611c61ba6a7b81fd53866c3cd0b9

Contents?: true

Size: 1022 Bytes

Versions: 5

Compression:

Stored size: 1022 Bytes

Contents

require 'spec_helper'

describe 'query caching' do
  let(:db_names) { [db1, db2] }

  before do
    Apartment.configure do |config|
      config.excluded_models = ["Company"]
      config.tenant_names = lambda{ Company.pluck(:database) }
      config.use_schemas = true
    end

    Apartment::Tenant.reload!(config)

    db_names.each do |db_name|
      Apartment::Tenant.create(db_name)
      Company.create database: db_name
    end
  end

  after do
    db_names.each{ |db| Apartment::Tenant.drop(db) }
    Apartment::Tenant.reset
    Company.delete_all
  end

  it 'clears the ActiveRecord::QueryCache after switching databases' do
    db_names.each do |db_name|
      Apartment::Tenant.switch db_name
      User.create! name: db_name
    end

    ActiveRecord::Base.connection.enable_query_cache!

    Apartment::Tenant.switch db_names.first
    User.find_by_name(db_names.first).name.should == db_names.first

    Apartment::Tenant.switch db_names.last
    User.find_by_name(db_names.first).should be_nil
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
apartment-0.26.1 spec/integration/query_caching_spec.rb
apartment-0.26.0 spec/integration/query_caching_spec.rb
apartment-0.25.2 spec/integration/query_caching_spec.rb
apartment-0.25.1 spec/integration/query_caching_spec.rb
apartment-0.25.0 spec/integration/query_caching_spec.rb