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:
parent
082326deb5
commit
7423a71fc0
3 changed files with 15 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue