From 5f3cf4244de4fd62049d08df4e6bf63c945ab90e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 4 Feb 2011 10:19:02 -0800 Subject: connection pool can cache column, table, and primary key information --- activerecord/test/cases/connection_pool_test.rb | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index 2e18117895..27fc3cab49 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/activerecord/test/cases/connection_pool_test.rb @@ -3,6 +3,41 @@ require "cases/helper" module ActiveRecord module ConnectionAdapters class ConnectionPoolTest < ActiveRecord::TestCase + def setup + # Keep a duplicate pool so we do not bother others + @pool = ConnectionPool.new ActiveRecord::Base.connection_pool.spec + end + + def test_pool_caches_columns + columns = @pool.columns['posts'] + assert_equal columns, @pool.columns['posts'] + end + + def test_pool_caches_columns_hash + columns_hash = @pool.columns_hash['posts'] + assert_equal columns_hash, @pool.columns_hash['posts'] + end + + def test_clearing_cache + @pool.columns['posts'] + @pool.columns_hash['posts'] + @pool.primary_keys['posts'] + + @pool.clear_cache! + + assert_equal 0, @pool.columns.size + assert_equal 0, @pool.columns_hash.size + assert_equal 0, @pool.primary_keys.size + end + + def test_primary_key + assert_equal 'id', @pool.primary_keys['posts'] + end + + def test_primary_key_for_non_existent_table + assert_equal 'id', @pool.primary_keys['omgponies'] + end + def test_clear_stale_cached_connections! pool = ConnectionPool.new ActiveRecord::Base.connection_pool.spec -- cgit v1.2.3