From 8113c8e1238939c8c68c2598b0a78a5b2171943d Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Thu, 4 Apr 2019 05:04:25 +0900 Subject: Clear query cache when truncate table(s) --- activerecord/test/cases/adapter_test.rb | 44 +++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index 2b20d842e8..ba04859bf0 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -485,23 +485,51 @@ module ActiveRecord 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 -- cgit v1.2.3