Sha256: b3b1b400149227c2baf1c59621812d00a693a0daf0173d2d0af0d031e91491f7

Contents?: true

Size: 975 Bytes

Versions: 3

Compression:

Stored size: 975 Bytes

Contents

require 'spec_helper'

describe 'query caching' do
  before do
    Apartment.configure do |config|
      config.excluded_models = ["Company"]
      config.database_names = lambda{ Company.scoped.collect(&:database) }
    end

    db_names.each do |db_name|
      Apartment::Database.create(db_name)
      Company.create :database => db_name
    end
  end

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

  let(:db_names) { 2.times.map{ Apartment::Test.next_db } }

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

    ActiveRecord::Base.connection.enable_query_cache!

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
apartment-0.22.1 spec/integration/query_caching_spec.rb
apartment-0.22.0 spec/integration/query_caching_spec.rb
apartment-0.21.1 spec/integration/query_caching_spec.rb