aboutsummaryrefslogblamecommitdiffstats
path: root/activerecord/test/cases/connection_adapters/schema_cache_test.rb
blob: d5ae08cd5889b0ea8366e4c847dece45bab57f98 (plain) (tree)
1
2
3
4
5
6
7
8







                                                  









                                                           





















                                                               
require "cases/helper"

module ActiveRecord
  module ConnectionAdapters
    class SchemaCacheTest < ActiveRecord::TestCase
      def setup
        connection = ActiveRecord::Base.connection
        @cache     = SchemaCache.new connection
      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_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