1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

allow AR caches to be cleared, clear them on class reloading

This commit is contained in:
Aaron Patterson 2011-02-03 15:35:34 -08:00
parent 082326deb5
commit 7423a71fc0
3 changed files with 15 additions and 0 deletions

View file

@ -750,6 +750,12 @@ module ActiveRecord #:nodoc:
@arel_engine = @relation = nil
end
def clear_cache! # :nodoc:
@@columns.clear
@@columns_hash.clear
@@arel_tables.clear
end
def reset_column_cache # :nodoc:
@@columns.delete table_name
@@columns_hash.delete table_name

View file

@ -72,6 +72,7 @@ module ActiveRecord
ActiveSupport.on_load(:active_record) do
ActionDispatch::Reloader.to_cleanup do
ActiveRecord::Base.clear_reloadable_connections!
ActiveRecord::Base.clear_cache!
end
end
end

View file

@ -1553,6 +1553,14 @@ class BasicsTest < ActiveRecord::TestCase
end
end
def test_clear_cache!
# preheat cache
c1 = Post.columns
ActiveRecord::Base.clear_cache!
c2 = Post.columns
assert_not_equal c1, c2
end
def test_default_scope_is_reset
Object.const_set :UnloadablePost, Class.new(ActiveRecord::Base)
UnloadablePost.table_name = 'posts'