提交 8113c8e1 编写于 作者: R Ryuta Kamizono

Clear query cache when truncate table(s)

上级 8be22161
......@@ -7,7 +7,8 @@ module ConnectionAdapters # :nodoc:
module QueryCache
class << self
def included(base) #:nodoc:
dirties_query_cache base, :insert, :update, :delete, :rollback_to_savepoint, :rollback_db_transaction
dirties_query_cache base, :insert, :update, :delete, :truncate, :truncate_tables,
:rollback_to_savepoint, :rollback_db_transaction
base.set_callback :checkout, :after, :configure_query_cache!
base.set_callback :checkin, :after, :disable_query_cache!
......
......@@ -485,23 +485,51 @@ def setup
end
def test_truncate
assert_operator @connection.query_value("SELECT COUNT(*) FROM posts"), :>, 0
assert_operator Post.count, :>, 0
@connection.truncate("posts")
assert_equal 0, @connection.query_value("SELECT COUNT(*) FROM posts")
assert_equal 0, Post.count
end
def test_truncate_with_query_cache
@connection.enable_query_cache!
assert_operator Post.count, :>, 0
@connection.truncate("posts")
assert_equal 0, Post.count
ensure
@connection.disable_query_cache!
end
def test_truncate_tables
assert_operator @connection.query_value("SELECT COUNT(*) FROM posts"), :>, 0
assert_operator @connection.query_value("SELECT COUNT(*) FROM authors"), :>, 0
assert_operator @connection.query_value("SELECT COUNT(*) FROM author_addresses"), :>, 0
assert_operator Post.count, :>, 0
assert_operator Author.count, :>, 0
assert_operator AuthorAddress.count, :>, 0
@connection.truncate_tables("author_addresses", "authors", "posts")
assert_equal 0, @connection.query_value("SELECT COUNT(*) FROM posts")
assert_equal 0, @connection.query_value("SELECT COUNT(*) FROM authors")
assert_equal 0, @connection.query_value("SELECT COUNT(*) FROM author_addresses")
assert_equal 0, Post.count
assert_equal 0, Author.count
assert_equal 0, AuthorAddress.count
end
def test_truncate_tables_with_query_cache
@connection.enable_query_cache!
assert_operator Post.count, :>, 0
assert_operator Author.count, :>, 0
assert_operator AuthorAddress.count, :>, 0
@connection.truncate_tables("author_addresses", "authors", "posts")
assert_equal 0, Post.count
assert_equal 0, Author.count
assert_equal 0, AuthorAddress.count
ensure
@connection.disable_query_cache!
end
# test resetting sequences in odd tables in PostgreSQL
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册