diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-11-19 20:19:53 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-11-19 20:19:53 -0800 |
commit | bd2f5c062da011e092c1f122567f24bd5fc6d9b5 (patch) | |
tree | 968c8e162f67157b4cad826ce1680310e70dd7c1 /activerecord/test/cases/connection_adapters | |
parent | 4cdd44e3e0e22742a6e0ddc67c388cee0c8c13db (diff) | |
download | rails-bd2f5c062da011e092c1f122567f24bd5fc6d9b5.tar.gz rails-bd2f5c062da011e092c1f122567f24bd5fc6d9b5.tar.bz2 rails-bd2f5c062da011e092c1f122567f24bd5fc6d9b5.zip |
pushing caching and visitors down to the connection
Diffstat (limited to 'activerecord/test/cases/connection_adapters')
-rw-r--r-- | activerecord/test/cases/connection_adapters/schema_cache_test.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/activerecord/test/cases/connection_adapters/schema_cache_test.rb b/activerecord/test/cases/connection_adapters/schema_cache_test.rb new file mode 100644 index 0000000000..79e842f5e1 --- /dev/null +++ b/activerecord/test/cases/connection_adapters/schema_cache_test.rb @@ -0,0 +1,55 @@ +require "cases/helper" + +module ActiveRecord + module ConnectionAdapters + class SchemaCacheTest < ActiveRecord::TestCase + def setup + connection = ActiveRecord::Base.connection + @cache = SchemaCache.new connection + + if in_memory_db? + connection.create_table :posts do |t| + t.integer :cololumn + end + end + end + + def test_primary_key + assert_equal 'id', @cache.primary_keys['posts'] + end + + def test_primary_key_for_non_existent_table + assert_equal 'id', @cache.primary_keys['omgponies'] + end + + def test_primary_key_is_set_on_columns + posts_columns = @cache.columns_hash['posts'] + assert posts_columns['id'].primary + + (posts_columns.keys - ['id']).each do |key| + assert !posts_columns[key].primary + end + end + + def test_caches_columns + columns = @cache.columns['posts'] + assert_equal columns, @cache.columns['posts'] + end + + def test_caches_columns_hash + columns_hash = @cache.columns_hash['posts'] + assert_equal columns_hash, @cache.columns_hash['posts'] + end + + def test_clearing_column_cache + @cache.columns['posts'] + @cache.columns_hash['posts'] + + @cache.clear! + + assert_equal 0, @cache.columns.size + assert_equal 0, @cache.columns_hash.size + end + end + end +end |